Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snow 1926267 test #1019

Closed
wants to merge 9 commits into from
Closed
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
12 changes: 6 additions & 6 deletions ci/container/test_component.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ if [[ -z "$GITHUB_ACTIONS" ]]; then
fi
fi

echo "[INFO] Running Tests: Test result: $WORKSPACE/junit.xml"
if ! ${MOCHA_CMD[@]} 'test/{unit,integration}/**/*.js'; then
echo "[ERROR] Test failed"
[[ -f "$WORKSPACE/junit.xml" ]] && cat $WORKSPACE/junit.xml
exit 1
fi
#echo "[INFO] Running Tests: Test result: $WORKSPACE/junit.xml"
#if ! ${MOCHA_CMD[@]} 'test/{unit,integration}/**/*.js'; then
# echo "[ERROR] Test failed"
# [[ -f "$WORKSPACE/junit.xml" ]] && cat $WORKSPACE/junit.xml
# exit 1
#fi
14 changes: 9 additions & 5 deletions lib/connection/result/row_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function RowStream(statement, context, options) {
} else if (context.isFetchingResult) {
// if we're still fetching the result, wait for the operation to complete
context.on('statement-complete', init);
} else if (context.result || isStatementErrorFatal(context.resultError)) {
} else if (context.result || isStatementErrorFatal(context)) {
// if we have a result or a fatal error, call init() in the next tick of
// the event loop
process.nextTick(init);
Expand Down Expand Up @@ -295,12 +295,16 @@ Util.inherits(RowStream, Readable);
/**
* Determines if a statement error is fatal.
*
* @param {Error} error
*
* @returns {Boolean}
* @param context
*/
function isStatementErrorFatal(error) {
return Errors.isOperationFailedError(error) && error.sqlState;
function isStatementErrorFatal(context) {
const error = context.resultError;
return (Errors.isOperationFailedError(error) && error.sqlState) || isFileUploadError(error, context.type);
}

function isFileUploadError(error, contextType) {
return error && contextType === 'FILE_PRE_EXEC';
}

/**
Expand Down
50 changes: 30 additions & 20 deletions lib/connection/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,26 +813,7 @@ function FileStatementPreExec(
* @param {Object} body
*/
context.onStatementRequestSucc = async function (body) {
context.fileMetadata = body;

const fta = new FileTransferAgent(context);
await fta.execute();

// build a result from the response
const result = fta.result();

// init result and meta
body.data.rowset = result.rowset;
body.data.returned = body.data.rowset.length;
body.data.rowtype = result.rowtype;
body.data.parameters = [];

context.result = new Result({
response: body,
statement: this,
services: context.services,
connectionConfig: context.connectionConfig
});
await executeFileTransferRequest(context, body, this);
};

/**
Expand All @@ -858,6 +839,35 @@ function FileStatementPreExec(
sendRequestPreExec(context, context.onStatementRequestComp);
}

async function executeFileTransferRequest(context, body, statement, fileTransferAgent) {
context.fileMetadata = body;

const fta = typeof fileTransferAgent === 'undefined' ? new FileTransferAgent(context) : fileTransferAgent;
await fta.execute();

try {
// build a result from the response
const result = fta.result();

// init result and meta
body.data.rowset = result.rowset;
body.data.returned = body.data.rowset.length;
body.data.rowtype = result.rowtype;
body.data.parameters = [];

context.result = new Result({
response: body,
statement: statement,
services: context.services,
connectionConfig: context.connectionConfig
});
} catch (error) {
context.resultError = error;
}
}

exports.executeFileTransferRequest = executeFileTransferRequest;

Util.inherits(FileStatementPreExec, BaseStatement);

/**
Expand Down
10 changes: 10 additions & 0 deletions lib/file_transfer_agent/file_transfer_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ function FileTransferAgent(context) {

if (results) {
for (const meta of results) {
if (meta['resultStatus'] === 'ERROR') {
errorDetails = meta['errorDetails'];
if (!errorDetails) {
errorDetails = `Unknown error during PUT of file: ${meta['srcFilePath'].toString()}`;
}
throw new Error(errorDetails);
}
if (meta['srcCompressionType']) {
srcCompressionType = meta['srcCompressionType']['name'];
} else {
Expand Down Expand Up @@ -334,6 +341,9 @@ function FileTransferAgent(context) {
continue;
}
results.push(result);
if (result['resultStatus'] === resultStatus.ERROR) {
break;
}
index += 1;
if (INJECT_WAIT_IN_PUT > 0) {
await new Promise(resolve => setTimeout(resolve, INJECT_WAIT_IN_PUT));
Expand Down
2 changes: 1 addition & 1 deletion system_test/testSystemGetObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const snowflake = require('./../lib/snowflake');
const connOptions = require('../test/integration/connectionOptions');
const testUtil = require('../test/integration/testUtil');

describe('system$get_objects()', function () {
describe.only('system$get_objects()', function () {
const createDatabase = 'create or replace database node_testdb;';
const createSchema = 'create or replace schema node_testschema;';
const createTableT1 = 'create or replace table t1 (c1 number);';
Expand Down
2 changes: 1 addition & 1 deletion system_test/testSystemSetWhSnowflakeSupportFlag.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const connOptions = require('../test/integration/connectionOptions');
const connOptionsInternal = require('./connectionOptions');
const testUtil = require('../test/integration/testUtil');

describe('exclude support warehouses', function () {
describe.only('exclude support warehouses', function () {
const createSysWh =
'create or replace warehouse syswh warehouse_size = \'xsmall\'';
const dropSysWh = 'drop warehouse syswh';
Expand Down
2 changes: 1 addition & 1 deletion test/integration/testConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Connection test', function () {
});
});

it('does not return tokens when not in qaMode', function () {
it.only('does not return tokens when not in qaMode', function () {
const connection = snowflake.createConnection(connOption.valid);
assert.deepEqual(connection.getTokens(), {});
});
Expand Down
17 changes: 17 additions & 0 deletions test/unit/connection/statement_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,20 @@ describe('Statement.fetchResult()', function () {
it(testCase.name, createItCallback(testCase));
}
});

it('Statement file transfer error', async function () {
const mockFta = {
execute: async function () {
return null;
},
result: function () {
throw new Error('some file transfer error');
}
};
const context = {};
const body = {
'data': {},
};
await Statement.executeFileTransferRequest(context, body, null, mockFta);
assert.strictEqual(context.resultError.message, 'some file transfer error');
});
Loading