Skip to content

Commit

Permalink
SNOW-728803: Set requestId the same for QA and non-QA mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lf committed Sep 27, 2023
1 parent faf116c commit 21f7044
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 92 deletions.
35 changes: 7 additions & 28 deletions lib/connection/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,35 +397,14 @@ function createContextPreExec(
Errors.assertInternal(Util.isObject(services));
Errors.assertInternal(Util.isObject(connectionConfig));

// if we're not in qa mode, use a random uuid for the statement request id
// or use request id passed by user
if (!connectionConfig.isQaMode())
{
if (statementOptions.requestId)
{
statementContext.requestId = statementOptions.requestId;
statementContext.resubmitRequest = true;
}
else
{
statementContext.requestId = uuidv4();
}
// use request id passed by user
if (statementOptions.requestId) {
statementContext.requestId = statementOptions.requestId;
statementContext.resubmitRequest = true;
}
else // we're in qa mode
{
// if a request id or sequence id are specified in the statement options,
// use them as is; this is to facilitate testing by making things more
// deterministic
if (Util.isString(statementOptions.requestId))
{
statementContext.requestId = statementOptions.requestId;
}

// SNOW-728803: In QA mode, set resubmitRequest to true to test that sqlText
// is not overwritten if a sqlText is already specified by the user
if (statementOptions.requestId === 'SNOW-728803-requestId') {
statementContext.resubmitRequest = true;
}
else {
// use a random uuid for the statement request id
statementContext.requestId = uuidv4();
}

return statementContext;
Expand Down
63 changes: 14 additions & 49 deletions test/unit/mock/mock_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ function buildRequestOutputMappings(clientInfo)
request:
{
method: 'POST',
url: 'http://fakeaccount.snowflakecomputing.com/queries/v1/query-request?requestId=',
url: 'http://fakeaccount.snowflakecomputing.com/queries/v1/query-request?requestId=SNOW-728803-requestId',
headers:
{
'Accept': 'application/snowflake',
Expand All @@ -723,14 +723,21 @@ function buildRequestOutputMappings(clientInfo)
err: null,
response:
{
statusCode: 401,
statusMessage: 'Unauthorized',
statusCode: 200,
statusMessage: 'OK',
body:
{
'data' : null,
'code': '390103',
'message': 'Session token not found in the request data.',
'success': false,
'data':
{
'parameters': [],
'rowtype': [],
'rowset': [['1']],
'total': 1,
'returned': 1
},
'message': null,
'code': null,
'success': true
}
}
}
Expand Down Expand Up @@ -766,48 +773,6 @@ function buildRequestOutputMappings(clientInfo)
}
}
},
{
request:
{
method: 'POST',
url: 'http://fakeaccount.snowflakecomputing.com/queries/v1/query-request?requestId=SNOW-728803-requestId',
headers:
{
'Accept': 'application/snowflake',
'Authorization': 'Snowflake Token="SESSION_TOKEN"',
'Content-Type': 'application/json'
},
json:
{
disableOfflineChunks: false,
sqlText: 'select 1;',
queryContextDTO: { entries: [] }
}
},
output:
{
err: null,
response:
{
statusCode: 200,
statusMessage: 'OK',
body:
{
'data':
{
'parameters': [],
'rowtype': [],
'rowset': [['1']],
'total': 1,
'returned': 1
},
'message': null,
'code': null,
'success': true
}
}
}
},
{
request:
{
Expand Down
16 changes: 1 addition & 15 deletions test/unit/snowflake_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -956,21 +956,7 @@ describe('connection.execute() with requestId', function () {
});
},
function (callback) {
// 1st request fails with an error
statement = connection.execute(
{
sqlText: sqlText,
complete: function (err, stmt) {
assert.ok(err, 'there should be an error');
assert.strictEqual(stmt, statement,
'the execute() callback should be invoked with the statement');

callback();
}
});
},
function (callback) {
// 2nd request with sqlText and requestId specified
// request with sqlText and requestId specified
statement = connection.execute(
{
sqlText: sqlText,
Expand Down

0 comments on commit 21f7044

Please sign in to comment.