Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/container/test_component.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ else
)
fi

echo "[INFO] Mocha CMD: $MOCHA_CMD"

if [[ -z "$GITHUB_ACTIONS" ]]; then
echo "[INFO] Running Internal Tests. Test result: $WORKSPACE/junit-system-test.xml"
if ! ${MOCHA_CMD[@]} "$SOURCE_ROOT/system_test/**/*.{js,ts}"; then
Expand Down
3 changes: 3 additions & 0 deletions lib/connection/connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -1129,15 +1129,18 @@ function createParameters() {
{
name: PARAM_RETRY_SF_MAX_NUM_RETRIES,
defaultValue: 1000,
external: true,
validate: isNonNegativeInteger
},
{
name: PARAM_RETRY_SF_STARTING_SLEEP_TIME,
defaultValue: 1,
external: true,
validate: isNonNegativeNumber
},
{
name: PARAM_RETRY_SF_MAX_SLEEP_TIME,
external: true,
Comment on lines 1130 to +1143
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since now PARAM_RETRY_SF_MAX_NUM_RETRIES , PARAM_RETRY_SF_STARTING_SLEEP_TIME, and PARAM_RETRY_SF_MAX_SLEEP_TIME will be public, my respectful request here would be that please make sure the parameters are correctly documented in Snowflake docs. Thank you in advance! 🙇

defaultValue: 16,
validate: isNonNegativeNumber
}
Expand Down
7 changes: 4 additions & 3 deletions lib/connection/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -1492,9 +1492,10 @@ function sendSfRequest(statementContext, options, appendQueryParamOnRetry) {
// if we haven't exceeded the maximum number of retries yet and the server
// came back with a retryable error code
if (numRetries < maxNumRetries &&
err && Util.isRetryableHttpError(
err.response, false // no retry for HTTP 403
)) {
err && (!err.response || (Util.isRetryableHttpError(err.response, false))
// || Util.isNetworkError(err)
)
) {
// increment the retry count
numRetries++;
lastStatusCodeForRetry = err.response ? err.response.statusCode : 0;
Expand Down
12 changes: 12 additions & 0 deletions test/authentication/connectionParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ const oauthOktaAuthorizationCode =
enableExperimentalAuthentication: true
};

const wiremock =
{
...baseParameters,
accessUrl: null,
username: 'MOCK_USERNAME',
account: 'MOCK_ACCOUNT_NAME',
host: 'localhost',
protocol: 'http',
authenticator: 'OAUTH',
};

exports.externalBrowser = externalBrowser;
exports.okta = okta;
exports.oauth = oauth;
Expand Down Expand Up @@ -220,3 +231,4 @@ exports.snowflakeAuthTestOauthOktaPassword = snowflakeAuthTestOauthOktaPassword;
exports.snowflakeAuthTestOauthOktaClientId = snowflakeAuthTestOauthOktaClientId;
exports.oauthSnowflakeWildcardsAuthorizationCode = oauthSnowflakeWildcardsAuthorizationCode;
exports.oauthOktaAuthorizationCode = oauthOktaAuthorizationCode;
exports.wiremock = wiremock;
64 changes: 64 additions & 0 deletions test/integration/testConnectionRetries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2015-2024 Snowflake Computing Inc. All rights reserved.
*/

const { runWireMockAsync, addWireMockMappingsFromFile } = require('../wiremockRunner');
const connParameters = require('../authentication/connectionParameters');
const testUtil = require('../integration/testUtil');
const snowflake = require('../../lib/snowflake');
const assert = require('assert');

describe('Connection test', function () {
this.timeout(500000);
let port;
let wireMock;

before(async () => {
port = await testUtil.getFreePort();
wireMock = await runWireMockAsync(port);
snowflake.configure({
logLevel: 'DEBUG',
disableOCSPChecks: true
});
});

afterEach(async () => {
wireMock.scenarios.resetAllScenarios();
});

after(async () => {
await wireMock.global.shutdown();
});

it('Test retries after connection reset - success', async function () {
await addWireMockMappingsFromFile(wireMock, 'wiremock/mappings/six_reset_connection_and_correct_response.json');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based only on mapping file name - should we also have a test, when it eventually ends up in connection reset propagated to the user?

const connectionOption = { ...connParameters.wiremock, password: 'MOCK_TOKEN', port: port, sfRetryMaxSleepTime: 2, sfRetryMaxNumRetries: 10 };
const connection = testUtil.createConnection(connectionOption);
await testUtil.connectAsync(connection);
await assert.doesNotReject(async () => await testUtil.executeCmdAsync(connection, ' Select 1'));
});

it('Test retries after malformed response', async function () {
await addWireMockMappingsFromFile(wireMock, 'wiremock/mappings/six_malformed_and_correct.json');
const connectionOption = { ...connParameters.wiremock, password: 'MOCK_TOKEN', port: port, sfRetryMaxSleepTime: 2 };
const connection = testUtil.createConnection(connectionOption);
await testUtil.connectAsync(connection);
await assert.doesNotReject(async () => await testUtil.executeCmdAsync(connection, ' Select 1'));
});

it('Test retries after connection reset - fail', async function () {
await addWireMockMappingsFromFile(wireMock, 'wiremock/mappings/six_reset_connection_and_correct_response.json');
const connectionOption = { ...connParameters.wiremock, password: 'MOCK_TOKEN', port: port, sfRetryMaxNumRetries: 1, sfRetryMaxSleepTime: 2 };
const connection = testUtil.createConnection(connectionOption);
await testUtil.connectAsync(connection);
await assert.rejects(
testUtil.executeCmdAsync(connection, ' Select 1'),
(err) => {
assert.match(err.message, /Network error. Could not reach Snowflake./);
return true;
},
);
});
});


14 changes: 2 additions & 12 deletions test/integration/wiremock/testWiremockRunner.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
const assert = require('assert');
const fs = require('fs');
const net = require('net');
const axios = require('axios');
const { runWireMockAsync } = require('../../wiremockRunner');
const os = require('os');

async function getFreePort() {
return new Promise(res => {
const srv = net.createServer();
srv.listen(0, () => {
const port = srv.address().port;
srv.close(() => res(port));
});
});
}
const testUtil = require('../testUtil');

if (os.platform !== 'win32') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a test for wiremock itself? Do we still need this?

describe('Wiremock test', function () {
let port, wireMock;
before(async () => {
port = await getFreePort();
port = await testUtil.getFreePort();
wireMock = await runWireMockAsync(port);
});
after(async () => {
Expand Down
Loading
Loading