Skip to content

Commit

Permalink
Merge dee170f into 10e0ce7
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcasalboni committed Jul 22, 2019
2 parents 10e0ce7 + dee170f commit 387d587
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
8 changes: 8 additions & 0 deletions lambda/executor.js
Expand Up @@ -68,6 +68,10 @@ const runInParallel = async(num, lambdaARN, lambdaAlias, payload) => {
// run all invocations in parallel ...
const invocations = utils.range(num).map(async() => {
const data = await utils.invokeLambda(lambdaARN, lambdaAlias, payload);
// invocation errors return 200 and contain FunctionError and Payload
if (data.FunctionError) {
throw new Error('Invocation error: ' + data.Payload);
}
results.push(data);
});
// ... and wait for results
Expand All @@ -80,6 +84,10 @@ const runInSeries = async(num, lambdaARN, lambdaAlias, payload) => {
for (let i = 0; i < num; i++) {
// run invocations in series
const data = await utils.invokeLambda(lambdaARN, lambdaAlias, payload);
// invocation errors return 200 and contain FunctionError and Payload
if (data.FunctionError) {
throw new Error('Invocation error: ' + data.Payload);
}
results.push(data);
}
return results;
Expand Down
44 changes: 37 additions & 7 deletions template.yml
Expand Up @@ -131,7 +131,7 @@ Resources:
"Type": "Parallel",
"Next": "After Branching",
"Catch": [{
"ErrorEquals": [ "States.ALL" ],
"ErrorEquals": ["States.ALL"],
"Next": "CleanUpOnError",
"ResultPath": "$.error"
}],
Expand All @@ -149,7 +149,12 @@ Resources:
"Type": "Task",
"Resource": "${executorArn}",
"ResultPath": "$.stats",
"End": true
"End": true,
"Retry": [{
"ErrorEquals": ["States.ALL"],
"IntervalSeconds": 3,
"MaxAttempts": 2
}]
}
}
},
Expand All @@ -166,7 +171,12 @@ Resources:
"Type": "Task",
"Resource": "${executorArn}",
"ResultPath": "$.stats",
"End": true
"End": true,
"Retry": [{
"ErrorEquals": ["States.ALL"],
"IntervalSeconds": 3,
"MaxAttempts": 2
}]
}
}
},
Expand All @@ -183,7 +193,12 @@ Resources:
"Type": "Task",
"Resource": "${executorArn}",
"ResultPath": "$.stats",
"End": true
"End": true,
"Retry": [{
"ErrorEquals": ["States.ALL"],
"IntervalSeconds": 3,
"MaxAttempts": 2
}]
}
}
},
Expand All @@ -200,7 +215,12 @@ Resources:
"Type": "Task",
"Resource": "${executorArn}",
"ResultPath": "$.stats",
"End": true
"End": true,
"Retry": [{
"ErrorEquals": ["States.ALL"],
"IntervalSeconds": 3,
"MaxAttempts": 2
}]
}
}
},
Expand All @@ -217,7 +237,12 @@ Resources:
"Type": "Task",
"Resource": "${executorArn}",
"ResultPath": "$.stats",
"End": true
"End": true,
"Retry": [{
"ErrorEquals": ["States.ALL"],
"IntervalSeconds": 3,
"MaxAttempts": 2
}]
}
}
},
Expand All @@ -234,7 +259,12 @@ Resources:
"Type": "Task",
"Resource": "${executorArn}",
"ResultPath": "$.stats",
"End": true
"End": true,
"Retry": [{
"ErrorEquals": ["States.ALL"],
"IntervalSeconds": 3,
"MaxAttempts": 2
}]
}
}
}
Expand Down
25 changes: 22 additions & 3 deletions test/test-lambda.js
Expand Up @@ -37,14 +37,18 @@ const invokeForSuccess = async(handler, event) => {
// utility to invoke handler (success case)
const invokeForFailure = async(handler, event) => {

let result;

try {
const result = await handler(event, fakeContext);
expect(result).to.be(null);
throw new Error('should have thrown an error, instead got: ', result);
result = await handler(event, fakeContext);
} catch (error) {
expect(error).to.not.be(null);
return error;
}

expect(result).to.be(null);
// throw new Error('should have thrown an error, instead got: ', result);

};


Expand Down Expand Up @@ -304,6 +308,21 @@ describe('Lambda Functions', async() => {
});
});

it('should report an error if invocation fails', async() => {
utils.invokeLambda = async() => {
return {
FunctionError: 'Unhandled',
Payload: '{"errorType": "MemoryError", "stackTrace": [["/var/task/lambda_function.py", 11, "lambda_handler", "blabla"], ["/var/task/lambda_function.py", 7, "blabla]]}',
};
};
await invokeForFailure(handler, {
lambdaARN: 'arnOK',
value: '1024',
num: 10,
});

});

it('should return price as output', async() => {
const stats = await invokeForSuccess(handler, {
lambdaARN: 'arnOK',
Expand Down

0 comments on commit 387d587

Please sign in to comment.