mirror of
https://github.com/serverless/serverless.git
synced 2026-02-01 16:07:28 +00:00
Test python implementation of get_remaining_time_in_millis
This commit is contained in:
parent
35102ee3e6
commit
5a61f6c756
0
lib/plugins/aws/invokeLocal/fixture/__init__.py
Normal file
0
lib/plugins/aws/invokeLocal/fixture/__init__.py
Normal file
11
lib/plugins/aws/invokeLocal/fixture/handler.py
Normal file
11
lib/plugins/aws/invokeLocal/fixture/handler.py
Normal file
@ -0,0 +1,11 @@
|
||||
from time import sleep
|
||||
|
||||
def withRemainingTime(event, context):
|
||||
start = context.get_remaining_time_in_millis()
|
||||
sleep(0.001)
|
||||
stop = context.get_remaining_time_in_millis()
|
||||
|
||||
return {
|
||||
"start": start,
|
||||
"stop": stop
|
||||
}
|
||||
@ -452,4 +452,35 @@ describe('AwsInvokeLocal', () => {
|
||||
expect(serverless.cli.consoleLog.lastCall.args[0]).to.contain('"errorMessage": "failed"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#invokeLocalPython', () => {
|
||||
beforeEach(() => {
|
||||
awsInvokeLocal.options = {
|
||||
functionObj: {
|
||||
name: '',
|
||||
},
|
||||
};
|
||||
|
||||
serverless.cli = new CLI(serverless);
|
||||
sinon.stub(serverless.cli, 'consoleLog');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
serverless.cli.consoleLog.restore();
|
||||
});
|
||||
|
||||
describe('context.remainingTimeInMillis', () => {
|
||||
it('should become lower over time', () => {
|
||||
awsInvokeLocal.serverless.config.servicePath = __dirname;
|
||||
|
||||
return awsInvokeLocal.invokeLocalPython(
|
||||
'python2.7',
|
||||
'fixture/handler',
|
||||
'withRemainingTime').then(() => {
|
||||
const remainingTimes = JSON.parse(serverless.cli.consoleLog.lastCall.args[0]);
|
||||
expect(remainingTimes.start).to.be.above(remainingTimes.stop);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -12,7 +12,7 @@ class FakeLambdaContext(object):
|
||||
self.timeout = timeout
|
||||
|
||||
def get_remaining_time_in_millis(self):
|
||||
return max((self.timeout * 1000) - (time() - self.created), 0)
|
||||
return int(max((self.timeout * 1000) - (int(round(time() * 1000)) - int(round(self.created * 1000))), 0))
|
||||
|
||||
@property
|
||||
def function_name(self):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user