File tree Expand file tree Collapse file tree 4 files changed +24
-3
lines changed
Tests/SwiftAwsLambdaTests Expand file tree Collapse file tree 4 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,14 @@ public enum Lambda {
118
118
logger [ metadataKey: " awsTraceId " ] = . string( traceId)
119
119
self . logger = logger
120
120
}
121
+
122
+ public func getRemainingTime( ) -> TimeAmount {
123
+ let deadline = self . deadline. millisSinceEpoch
124
+ let now = DispatchWallTime . now ( ) . millisSinceEpoch
125
+
126
+ let remaining = deadline - now
127
+ return . milliseconds( remaining)
128
+ }
121
129
}
122
130
123
131
private final class Lifecycle {
Original file line number Diff line number Diff line change @@ -130,7 +130,7 @@ private extension Lambda.Context {
130
130
self . init ( requestId: invocation. requestId,
131
131
traceId: invocation. traceId,
132
132
invokedFunctionArn: invocation. invokedFunctionArn,
133
- deadline: DispatchWallTime ( millisSinceEpoch: invocation. deadline ) ,
133
+ deadline: DispatchWallTime ( millisSinceEpoch: invocation. deadlineInMillisSinceEpoch ) ,
134
134
cognitoIdentity: invocation. cognitoIdentity,
135
135
clientContext: invocation. clientContext,
136
136
logger: logger)
Original file line number Diff line number Diff line change @@ -181,7 +181,7 @@ private extension HTTPClient.Response {
181
181
182
182
internal struct Invocation {
183
183
let requestId : String
184
- let deadline : Int64
184
+ let deadlineInMillisSinceEpoch : Int64
185
185
let invokedFunctionArn : String
186
186
let traceId : String
187
187
let clientContext : String ?
@@ -206,7 +206,7 @@ internal struct Invocation {
206
206
}
207
207
208
208
self . requestId = requestId
209
- self . deadline = unixTimeInMilliseconds
209
+ self . deadlineInMillisSinceEpoch = unixTimeInMilliseconds
210
210
self . invokedFunctionArn = invokedFunctionArn
211
211
self . traceId = traceId
212
212
self . clientContext = headers [ " Lambda-Runtime-Client-Context " ] . first
Original file line number Diff line number Diff line change @@ -252,6 +252,19 @@ class LambdaTest: XCTestCase {
252
252
logger: logger)
253
253
XCTAssertLessThan ( expiredContext. deadline, . now( ) )
254
254
}
255
+
256
+ func testGetRemainingTime( ) {
257
+ let logger = Logger ( label: " test " )
258
+ let context = Lambda . Context ( requestId: UUID ( ) . uuidString,
259
+ traceId: UUID ( ) . uuidString,
260
+ invokedFunctionArn: UUID ( ) . uuidString,
261
+ deadline: . now( ) + . seconds( 1 ) ,
262
+ cognitoIdentity: nil ,
263
+ clientContext: nil ,
264
+ logger: logger)
265
+ XCTAssertLessThanOrEqual ( context. getRemainingTime ( ) , . seconds( 1 ) )
266
+ XCTAssertGreaterThan ( context. getRemainingTime ( ) , . milliseconds( 800 ) )
267
+ }
255
268
}
256
269
257
270
private struct Behavior : LambdaServerBehavior {
You can’t perform that action at this time.
0 commit comments