From a063abd57932c0c04166901b0b352619a1c5c928 Mon Sep 17 00:00:00 2001 From: Alka Trivedi Date: Tue, 16 Apr 2024 11:35:24 +0530 Subject: [PATCH] tests: add integration and unit test for getTransaction options properties --- system-test/spanner.ts | 20 ++++++++++++++++++++ test/spanner.ts | 7 +++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/system-test/spanner.ts b/system-test/spanner.ts index 8849f6e2b..7323cfa80 100644 --- a/system-test/spanner.ts +++ b/system-test/spanner.ts @@ -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); + } + catch (err) { + if ((err as grpc.ServiceError).code === grpc.status.ABORTED) { + assert.ok(err, "Transaction is aborted"); + } else { + console.log("ERROR: ", err); + } + } + finally{ + transaction.end(); + } + }); + it('POSTGRESQL should throw an error for mismatched columns', function (done) { if (IS_EMULATOR_ENABLED) { this.skip(); diff --git a/test/spanner.ts b/test/spanner.ts index 8ad508c9c..86fe3bf71 100644 --- a/test/spanner.ts +++ b/test/spanner.ts @@ -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'}}); const transaction = promise[0]; await transaction.run('SELECT 1').then(results => { const request = spannerMock.getRequests().find(val => { @@ -3299,6 +3299,9 @@ describe('Spanner with mock server', () => { request.transaction!.begin!.readWrite!.readLockMode, 'OPTIMISTIC' ); + assert.strictEqual( + request.requestOptions?.transactionTag, 'transaction-tag' + ); }); });