Skip to content

Commit

Permalink
SNOW-1843504 - Testing resubmitting requests using request id (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pmotacki authored Dec 5, 2024
1 parent 2ec8d4a commit cf7b3a3
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
67 changes: 66 additions & 1 deletion test/integration/testExecute.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,5 +431,70 @@ describe('Execute test - variant', function () {

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

describe( '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, 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');
await testUtil.destroyConnectionAsync(firstConnection);
await testUtil.destroyConnectionAsync(secondConnection);
});

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

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

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

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

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

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

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

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

result = await testUtil.executeCmdAsyncWithAdditionalParameters(firstConnection, 'SELECT * from test_request_id ;');
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 executeCmdAsyncWithAdditionalParameters = function (connection, sqlText, additionalParameters) {
return new Promise((resolve, reject) => {
const executeParams = { ...{
sqlText: sqlText,
complete: (err, rowStatement, rows) =>
err ? reject(err) : resolve({ rowStatement: rowStatement, rows: rows })
}, ...additionalParameters };
connection.execute(executeParams);
});
};

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

0 comments on commit cf7b3a3

Please sign in to comment.