Skip to content

Commit

Permalink
tests: add integration and unit test for getTransaction options prope…
Browse files Browse the repository at this point in the history
…rties
  • Loading branch information
alkatrivedi committed Apr 16, 2024
1 parent e937ba8 commit a063abd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 20 additions & 0 deletions system-test/spanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8894,6 +8894,26 @@ describe('Spanner', () => {
mismatchedColumnError(done, DATABASE, googleSqlTable);
});

it('GOOGLE_STANDARD_SQL should use getTransaction for executing sql', async () => {
const promise = await DATABASE.getTransaction({optimisticLock: true});
const transaction = promise[0];

try {
const [rows] = await transaction!.run('SELECT * FROM TxnTable');
assert.strictEqual(rows.length, googleSqlRecords.length);
}

Check failure on line 8904 in system-test/spanner.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎·······`
catch (err) {
if ((err as grpc.ServiceError).code === grpc.status.ABORTED) {
assert.ok(err, "Transaction is aborted");

Check failure on line 8907 in system-test/spanner.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"Transaction·is·aborted"` with `'Transaction·is·aborted'`

Check warning on line 8907 in system-test/spanner.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
} else {
console.log("ERROR: ", err);

Check failure on line 8909 in system-test/spanner.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"ERROR:·"` with `'ERROR:·'`

Check warning on line 8909 in system-test/spanner.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
}
}

Check failure on line 8911 in system-test/spanner.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎········finally` with `·finally·`
finally{
transaction.end();
}
});

it('POSTGRESQL should throw an error for mismatched columns', function (done) {
if (IS_EMULATOR_ENABLED) {
this.skip();
Expand Down
7 changes: 5 additions & 2 deletions test/spanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3286,9 +3286,9 @@ describe('Spanner with mock server', () => {
});
});

it('should use optimistic lock for getTransaction', async () => {
it('should use optimistic lock and transaction tag for getTransaction', async () => {
const database = newTestDatabase();
const promise = await database.getTransaction({optimisticLock: true});
const promise = await database.getTransaction({optimisticLock: true, requestOptions: {transactionTag: 'transaction-tag'}});

Check failure on line 3291 in test/spanner.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `optimisticLock:·true,·requestOptions:·{transactionTag:·'transaction-tag'}` with `⏎········optimisticLock:·true,⏎········requestOptions:·{transactionTag:·'transaction-tag'},⏎······`
const transaction = promise[0];
await transaction.run('SELECT 1').then(results => {

Check warning on line 3293 in test/spanner.ts

View workflow job for this annotation

GitHub Actions / lint

'results' is defined but never used
const request = spannerMock.getRequests().find(val => {
Expand All @@ -3299,6 +3299,9 @@ describe('Spanner with mock server', () => {
request.transaction!.begin!.readWrite!.readLockMode,
'OPTIMISTIC'
);
assert.strictEqual(
request.requestOptions?.transactionTag, 'transaction-tag'

Check failure on line 3303 in test/spanner.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎·········`
);
});
});

Expand Down

0 comments on commit a063abd

Please sign in to comment.