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 4, 2024
1 parent c0ca935 commit 86c48e3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
23 changes: 12 additions & 11 deletions test/integration/testExecute.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,58 +455,59 @@ describe('Execute test - variant', function () {

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

Check failure on line 458 in test/integration/testExecute.js

View workflow job for this annotation

GitHub Actions / Run lint

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

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

await testUtil.executeCmdAsyncWithMoreParameters(firstConnection, 'SELECT * from test_request_id ;')
await testUtil.executeCmdAsyncWithAdditionalParameters(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.executeCmdAsyncWithMoreParameters(firstConnection, 'INSERT INTO test_request_id VALUES (\'testValue\');')
await testUtil.executeCmdAsyncWithAdditionalParameters(firstConnection, 'INSERT INTO test_request_id VALUES (\'testValue\');')
.then((result) => {
requestId = result.rowStatement.getRequestId();
});

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

await testUtil.executeCmdAsyncWithMoreParameters(firstConnection, 'SELECT * from test_request_id ;')
await testUtil.executeCmdAsyncWithAdditionalParameters(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.executeCmdAsyncWithMoreParameters(firstConnection, 'INSERT INTO test_request_id VALUES (\'testValue\');');
await testUtil.executeCmdAsyncWithMoreParameters(firstConnection, 'SELECT * from test_request_id;')
await testUtil.executeCmdAsyncWithAdditionalParameters(firstConnection, 'INSERT INTO test_request_id VALUES (\'testValue\');');
await testUtil.executeCmdAsyncWithAdditionalParameters(firstConnection, 'SELECT * from test_request_id;')
.then((result) => {
assert.strictEqual(result.rows.length, 1);
requestId = result.rowStatement.getRequestId();
});

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

await testUtil.executeCmdAsyncWithMoreParameters(firstConnection, 'SELECT * from test_request_id ;')
await testUtil.executeCmdAsyncWithAdditionalParameters(firstConnection, 'SELECT * from test_request_id ;')
.then((result) => {
assert.strictEqual(result.rows.length, 2);
});
Expand Down
6 changes: 3 additions & 3 deletions test/integration/testUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ const executeCmdAsync = function (connection, sqlText, binds = undefined) {

module.exports.executeCmdAsync = executeCmdAsync;

const executeCmdAsyncWithMoreParameters = function (connection, sqlText, moreParameters) {
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 })
}, ...moreParameters };
}, ...additionalParameters };
connection.execute(executeParams);
});
};

module.exports.executeCmdAsyncWithMoreParameters = executeCmdAsyncWithMoreParameters;
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 86c48e3

Please sign in to comment.