Skip to content

Commit

Permalink
test: deflake autocommit sample test (#255)
Browse files Browse the repository at this point in the history
* test: deflake autocommit sample test

* test: fix DDL call

Co-authored-by: larkee <larkee@users.noreply.github.com>
  • Loading branch information
larkee and larkee committed Mar 9, 2021
1 parent 215aaae commit 09099e9
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions samples/samples/autocommit_test.py
Expand Up @@ -8,8 +8,6 @@

from google.api_core.exceptions import Aborted
from google.cloud import spanner
from google.cloud.spanner_dbapi import connect
import mock
import pytest
from test_utils.retry import RetryErrors

Expand Down Expand Up @@ -53,13 +51,13 @@ def database(spanner_instance):

@RetryErrors(exception=Aborted, max_tries=2)
def test_enable_autocommit_mode(capsys, database):
connection = connect(INSTANCE_ID, DATABASE_ID)
cursor = connection.cursor()

with mock.patch(
"google.cloud.spanner_dbapi.connection.Cursor", return_value=cursor,
):
autocommit.enable_autocommit_mode(INSTANCE_ID, DATABASE_ID)
out, _ = capsys.readouterr()
assert "Autocommit mode is enabled." in out
assert "SingerId: 13, AlbumId: Russell, AlbumTitle: Morales" in out
# Delete table if it exists for retry attempts.
table = database.table('Singers')
if table.exists():
op = database.update_ddl(["DROP TABLE Singers"])
op.result()

autocommit.enable_autocommit_mode(INSTANCE_ID, DATABASE_ID)
out, _ = capsys.readouterr()
assert "Autocommit mode is enabled." in out
assert "SingerId: 13, AlbumId: Russell, AlbumTitle: Morales" in out

0 comments on commit 09099e9

Please sign in to comment.