forked from aws/aws-lambda-nodejs-runtime-interface-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvokeContextTest.js
37 lines (29 loc) · 1.03 KB
/
InvokeContextTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*/
'use strict';
require('should');
const sleep = require('util').promisify(setTimeout);
let InvokeContext = require('lambda-runtime/InvokeContext');
describe('Getting remaining invoke time', () => {
it('should reduce by at least elapsed time', async () => {
let ctx = new InvokeContext({
'lambda-runtime-deadline-ms': Date.now() + 1000,
});
const timeout = 100;
let before = ctx._headerData().getRemainingTimeInMillis();
await sleep(timeout + 10);
let after = ctx._headerData().getRemainingTimeInMillis();
(before - after).should.greaterThanOrEqual(
timeout - 1 /* Timers are not precise, allow 1 ms drift */,
);
});
it('should be within range', () => {
let ctx = new InvokeContext({
'lambda-runtime-deadline-ms': Date.now() + 1000,
});
let remainingTime = ctx._headerData().getRemainingTimeInMillis();
remainingTime.should.greaterThan(0);
remainingTime.should.lessThanOrEqual(1000);
});
});