Skip to content

Commit

Permalink
SNOW-1843504 - Testing resubmitting requests using request id
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pmotacki committed Dec 3, 2024
1 parent 599e55c commit 57caf29
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/file_transfer_agent/azure_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function AzureUtil(azure, filestream) {
blobContentEncoding: 'UTF-8',
blobContentType: 'application/octet-stream'
}
});
});
} catch (err) {
if (err['statusCode'] === 403 && detectAzureTokenExpireError(err)) {
meta['lastError'] = err;
Expand Down
83 changes: 82 additions & 1 deletion test/integration/testExecute.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,5 +431,86 @@ describe('Execute test - variant', function () {

it(testCase.name, createItCallback(testCase, rowAsserts));
});
});

describe.only( 'connection.execute() Resubmitting requests using requestId and different connections', function () {
const createTable = 'create or replace table test_request_id(colA string)';
let firstConnection;
let secondConnection;
before(async () => {
firstConnection = testUtil.createConnection();
secondConnection = testUtil.createConnection();
await testUtil.connectAsync(firstConnection);
await testUtil.connectAsync(secondConnection);
await testUtil.executeCmdAsync(firstConnection, 'truncate table if exists test_request_id');
await testUtil.executeCmdAsync(firstConnection, createTable);
});

beforeEach(async () => {
await testUtil.executeCmdAsync(firstConnection, 'truncate table if exists test_request_id');
});

after(async () => {
await testUtil.executeCmdAsync(firstConnection, 'drop table if exists test_request_id');
});

it('Do not INSERT twice when the same request id and connection', async () => {
let requestId;
await testUtil.executeCmdAsyncWithRequestId(firstConnection, 'INSERT INTO test_request_id VALUES (\'testValue\');')
.then((result) => {
requestId = result.rowStatement.getRequestId();
});

await testUtil.executeCmdAsyncWithRequestId(firstConnection, 'INSERT INTO test_request_id VALUES (\'testValue\');', requestId)
.then((result) => {
assert.strictEqual(result.rowStatement.getRequestId(), requestId);
});

await testUtil.executeCmdAsyncWithRequestId(firstConnection, 'SELECT * from test_request_id ;')
.then((result) => {
assert.strictEqual(result.rows.length, 1);
});
});

it('Execute INSERT for the same request id and different connection', async () => {
let requestId;
await testUtil.executeCmdAsyncWithRequestId(firstConnection, 'INSERT INTO test_request_id VALUES (\'testValue\');')
.then((result) => {
requestId = result.rowStatement.getRequestId();
});

await testUtil.executeCmdAsyncWithRequestId(secondConnection, 'INSERT INTO test_request_id VALUES (\'testValue\');', requestId)
.then((result) => {
assert.strictEqual(result.rowStatement.getRequestId(), requestId);
});

await testUtil.executeCmdAsyncWithRequestId(firstConnection, 'SELECT * from test_request_id ;')
.then((result) => {
assert.strictEqual(result.rows.length, 2);
});
});

it('Execute SELECT for the same request id and different data', async () => {
let requestId;
await testUtil.executeCmdAsyncWithRequestId(firstConnection, 'INSERT INTO test_request_id VALUES (\'testValue\');');
await testUtil.executeCmdAsyncWithRequestId(firstConnection, 'SELECT * from test_request_id;')
.then((result) => {
assert.strictEqual(result.rows.length, 1);
requestId = result.rowStatement.getRequestId();
});

await testUtil.executeCmdAsyncWithRequestId(firstConnection, 'INSERT INTO test_request_id VALUES (\'testValue\');');
await testUtil.executeCmdAsyncWithRequestId(firstConnection, 'SELECT * from test_request_id;', requestId)
.then((result) => {
assert.strictEqual(result.rows.length, 1);
});

await testUtil.executeCmdAsyncWithRequestId(firstConnection, 'SELECT * from test_request_id ;')
.then((result) => {
assert.strictEqual(result.rows.length, 2);
});
});
});



});
12 changes: 12 additions & 0 deletions test/integration/testUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ const executeCmdAsync = function (connection, sqlText, binds = undefined) {

module.exports.executeCmdAsync = executeCmdAsync;

const executeCmdAsyncWithRequestId = function (connection, sqlText, requestId) {
return new Promise((resolve, reject) => {
connection.execute({
sqlText: sqlText,
requestId: requestId,
complete: (err, rowStatement, rows) =>
err ? reject(err) : resolve({ rowStatement: rowStatement, rows: rows })
});
});
};

module.exports.executeCmdAsyncWithRequestId = executeCmdAsyncWithRequestId;
/**
* Drop tables one by one if exist - any connection error is ignored
* @param connection Connection
Expand Down

0 comments on commit 57caf29

Please sign in to comment.