File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Tests/AWSLambdaRuntimeTests Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ import Testing
16
16
17
17
@testable import AWSLambdaRuntime
18
18
19
+ #if canImport(FoundationEssentials)
20
+ import FoundationEssentials
21
+ #else
22
+ import Foundation
23
+ #endif
24
+
19
25
@Suite ( " LambdaClock Tests " )
20
26
struct LambdaClockTests {
21
27
@@ -108,4 +114,26 @@ struct LambdaClockTests {
108
114
#expect( remainingTime < . zero)
109
115
#expect( remainingTime <= . seconds( - 29 ) ) // Allow some timing tolerance
110
116
}
117
+
118
+ @Test ( " LambdaClock now matches Foundation Date within tolerance " )
119
+ func lambdaClockNowMatchesFoundationDate( ) {
120
+
121
+ let clock = LambdaClock ( )
122
+
123
+ // Get timestamps as close together as possible
124
+ let lambdaClockNow = clock. now
125
+ let foundationDate = Date ( )
126
+
127
+ // Convert Foundation Date to milliseconds since epoch
128
+ let foundationMillis = Int64 ( foundationDate. timeIntervalSince1970 * 1000 )
129
+ let lambdaClockMillis = lambdaClockNow. millisecondsSinceEpoch ( )
130
+
131
+ // Allow small tolerance for timing differences between calls
132
+ let difference = abs ( foundationMillis - lambdaClockMillis)
133
+
134
+ #expect(
135
+ difference <= 10 ,
136
+ " LambdaClock and Foundation Date should be within 10ms of each other, difference was \( difference) ms "
137
+ )
138
+ }
111
139
}
You can’t perform that action at this time.
0 commit comments