Skip to content

Commit

Permalink
Jk/cumulus 3315 (#3407)
Browse files Browse the repository at this point in the history
* CUMULUS-3135 - Update integration test scripts to fail on test timeout (#3401)

* Update integration test scripts to fail on test timeout

* Fixup

* Fixup

* Update script interpreter for test runs

* Fix script

* Fixup

* Fixup

* Update timeout pass/fail conditional

* Jk/cumulus 3135 fix integration tests (#3403)

* Update integration test scripts to fail on test timeout

* Fixup

* Fixup

* Update script interpreter for test runs

* Fix script

* Fixup

* Fixup

* Update api/client and integration test usage of it to fix test failures

* Fix formatting/lint/etc

* Update test/minor fix

---------

Co-authored-by: etcart <[email protected]>

---------

Co-authored-by: etcart <[email protected]>
  • Loading branch information
Jkovarik and etcart authored Jun 12, 2023
1 parent c4da56a commit c60a2a9
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 20 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ Users/clients that do not make use of these endpoints will not be impacted.

### Changed

**CUMULUS-3307**
- **CUMULUS-3315**
- Updated `@cumulus/api-client/granules.bulkOperation` to remove `ids`
parameter in favor of `granules` parameter, in the form of a
`@cumulus/types/ApiGranule` that requires the following keys: `[granuleId, collectionId]`
- **CUMULUS-3307**
- Pinned cumulus dependency on `pg` to `v8.10.x`
- **CUMULUS-3279**
- Updated core dependencies on `xml2js` to `v0.5.0`
Expand All @@ -211,6 +215,10 @@ Users/clients that do not make use of these endpoints will not be impacted.

### Fixed

- **CUMULUS-3315**
- Update CI scripts to use shell logic/GNU timeout to bound test timeouts
instead of NPM `parallel` package, as timeouts were not resulting in
integration test failure
- **CUMULUS-3223**
- Update `@cumulus/cmrjs/cmr-utils.getGranuleTemporalInfo` to handle the error when the cmr file s3url is not available
- Update `sfEventSqsToDbRecords` lambda to return [partial batch failure](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting),
Expand Down
18 changes: 11 additions & 7 deletions example/scripts/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

set +e

specName=$(echo "$2" | rev | cut -d'/' -f 1 | cut -d'.' -f 2 | rev)
specName=$(echo "$3" | rev | cut -d'/' -f 1 | cut -d'.' -f 2 | rev)
outputPath="${1}/${specName}-running.txt"
testTimeout=$2

TIMESTAMP=$(date "+%Y-%m-%dT%H:%M:%S")
echo "$TIMESTAMP ../node_modules/.bin/jasmine $2 STARTED"

../node_modules/.bin/jasmine --no-color "$2" > "$outputPath" 2>&1
echo "$TIMESTAMP ../node_modules/.bin/jasmine $3 STARTED"
timeout "$testTimeout" ../node_modules/.bin/jasmine --no-color "$3" > "$outputPath" 2>&1
result=$?

TIMESTAMP=$(date "+%Y-%m-%dT%H:%M:%S")
if [ "$result" -eq "0" ]; then
echo "$TIMESTAMP ../node_modules/.bin/jasmine $2 PASSED"
echo "$TIMESTAMP ../node_modules/.bin/jasmine $3 PASSED"
mv "$outputPath" "$1/${specName}-passed.txt"
elif { [ "$result" -gt "124" ] && [ "$result" -lt "128" ] ;} || [ "$result" -eq "137" ]; then
echo "$TIMESTAMP ../node_modules/.bin/jasmine $3 FAILED -- TIMEOUT"
mv "$outputPath" "$1/${specName}-failed.txt"
result=1
else
echo "$TIMESTAMP ../node_modules/.bin/jasmine $2 FAILED"
echo "$TIMESTAMP ../node_modules/.bin/jasmine $3 FAILED"
mv "$outputPath" "$1/${specName}-failed.txt"
fi

exit $result
exit $result
3 changes: 2 additions & 1 deletion example/scripts/tests-parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ DOT_PID="$!"

TESTS=$(find spec/parallel -type f -name '*spec.js' -or -name '*Spec.js')
testOutputDir=scripts/test_output
testTimeout=1200

rm -r -f $testOutputDir
mkdir -p $testOutputDir

echo "" | ../node_modules/.bin/parallel -j "${INTEGRATION_CONCURRENCY:=0}" --timeout 1200 sh scripts/run_test.sh $testOutputDir ::: $TESTS
echo "" | ../node_modules/.bin/parallel -j "${INTEGRATION_CONCURRENCY:=0}" sh scripts/run_test.sh $testOutputDir $testTimeout ::: $TESTS
result=$?
echo parallel tests complete: $result suite failures

Expand Down
18 changes: 14 additions & 4 deletions example/spec/parallel/ingestGranule/IngestGranuleSuccessSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ describe('The S3 Ingest Granules workflow', () => {

let beforeAllError;
let collection;
let collectionId;
let config;
let expectedPayload;
let expectedS3TagSet;
Expand All @@ -140,7 +141,7 @@ describe('The S3 Ingest Granules workflow', () => {
testDataFolder = createTestDataPath(testId);

collection = { name: `MOD09GQ${testSuffix}`, version: '006' };
const newCollectionId = constructCollectionId(collection.name, collection.version);
collectionId = constructCollectionId(collection.name, collection.version);
provider = { id: `s3_provider${testSuffix}` };

process.env.system_bucket = config.bucket;
Expand Down Expand Up @@ -193,7 +194,7 @@ describe('The S3 Ingest Granules workflow', () => {
},
});

expectedSyncGranulePayload = loadFileWithUpdatedGranuleIdPathAndCollection(templatedSyncGranuleFilename, granuleId, testDataFolder, newCollectionId, config.stackName);
expectedSyncGranulePayload = loadFileWithUpdatedGranuleIdPathAndCollection(templatedSyncGranuleFilename, granuleId, testDataFolder, collectionId, config.stackName);

expectedSyncGranulePayload.granules[0].dataType += testSuffix;
expectedSyncGranulePayload.granules[0].files[0].checksumType = inputPayload.granules[0].files[0].checksumType;
Expand Down Expand Up @@ -231,7 +232,7 @@ describe('The S3 Ingest Granules workflow', () => {
},
});

expectedPayload = loadFileWithUpdatedGranuleIdPathAndCollection(templatedOutputPayloadFilename, granuleId, testDataFolder, newCollectionId);
expectedPayload = loadFileWithUpdatedGranuleIdPathAndCollection(templatedOutputPayloadFilename, granuleId, testDataFolder, collectionId);
expectedPayload.granules[0].dataType += testSuffix;

// process.env.DISTRIBUTION_ENDPOINT needs to be set for below
Expand Down Expand Up @@ -932,7 +933,16 @@ describe('The S3 Ingest Granules workflow', () => {
bulkReingestResponse = await bulkReingestGranules({
prefix: config.stackName,
body: {
ids: [reingestGranuleId, fakeGranuleId],
granules: [
{
collectionId,
granuleId: reingestGranuleId,
},
{
collectionId,
granuleId: fakeGranuleId,
},
],
},
});
} catch (error) {
Expand Down
6 changes: 5 additions & 1 deletion example/spec/parallel/orca/OrcaBackupAndRecoverySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
waitForCompletedExecution,
} = require('@cumulus/integration-tests');
const { LambdaStep } = require('@cumulus/integration-tests/sfnStep');
const { constructCollectionId } = require('@cumulus/message/Collections');

const { removeCollectionAndAllDependencies } = require('../../helpers/Collections');
const { buildAndStartWorkflow } = require('../../helpers/workflowUtils');
Expand Down Expand Up @@ -163,7 +164,10 @@ describe('The S3 Ingest Granules workflow', () => {

const response = await bulkOperation({
prefix: config.stackName,
ids: [granuleId],
granules: [{
granuleId,
collectionId: constructCollectionId(collection.name, collection.version),
}],
workflowName: recoveryWorkflowName,
});

Expand Down
12 changes: 6 additions & 6 deletions packages/api-client/src/granules.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pRetry from 'p-retry';

import { ApiGranuleRecord, GranuleId, GranuleStatus } from '@cumulus/types/api/granules';
import { ApiGranuleRecord, ApiGranule, GranuleId, GranuleStatus } from '@cumulus/types/api/granules';
import { CollectionId } from '@cumulus/types/api/collections';
import Logger from '@cumulus/logger';

Expand Down Expand Up @@ -612,7 +612,7 @@ export const associateExecutionWithGranule = async (params: {
*/
export const bulkGranules = async (params: {
prefix: string,
body: object,
body: unknown,
callback?: InvokeApiFunction
}): Promise<ApiGatewayLambdaHttpProxyResponse> => {
const { prefix, body, callback = invokeApi } = params;
Expand Down Expand Up @@ -693,7 +693,7 @@ export const bulkReingestGranules = async (params: {
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {Array<string>} params.ids - the granules to have bulk operation on
* @param {Array<ApiGranuleRecord>} params.granules - the granules to have bulk operation on
* @param {string} params.workflowName - workflowName for the bulk operation execution
* @param {Function} params.callback - async function to invoke the api lambda
* that takes a prefix / user payload. Defaults
Expand All @@ -703,11 +703,11 @@ export const bulkReingestGranules = async (params: {
*/
export const bulkOperation = async (params: {
prefix: string,
ids: string[],
granules: ApiGranule[],
workflowName: string,
callback?: InvokeApiFunction
}): Promise<ApiGatewayLambdaHttpProxyResponse> => {
const { prefix, ids, workflowName, callback = invokeApi } = params;
const { prefix, granules, workflowName, callback = invokeApi } = params;
return await callback({
prefix: prefix,
payload: {
Expand All @@ -717,7 +717,7 @@ export const bulkOperation = async (params: {
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ ids, workflowName }),
body: JSON.stringify({ granules, workflowName }),
},
expectedStatusCodes: 202,
});
Expand Down
35 changes: 35 additions & 0 deletions packages/api-client/tests/test-granules.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,38 @@ test('associateExecutionWithGranule calls the callback with the expected object'
body,
}));
});

test('bulkOperation calls the callback with the expected object', async (t) => {
const workflowName = randomId('workflowName');
const granuleId = t.context.granuleId;
const collectionId = randomId('collectionId');
const granules = [{ granuleId, collectionId }];

const expected = {
prefix: t.context.testPrefix,
payload: {
httpMethod: 'POST',
resource: '/{proxy+}',
path: '/granules/bulk/',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
granules,
workflowName,
}),
},
expectedStatusCodes: 202,
};

const callback = (configObject) => {
t.deepEqual(configObject, expected);
};

await t.notThrowsAsync(
granulesApi.bulkOperation({
callback,
prefix: t.context.testPrefix,
granules,
workflowName,
})
);
});

0 comments on commit c60a2a9

Please sign in to comment.