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
1616
1717@testable import AWSLambdaRuntime
1818
19+ #if canImport(FoundationEssentials)
20+ import FoundationEssentials
21+ #else
22+ import Foundation
23+ #endif
24+
1925@Suite ( " LambdaClock Tests " )
2026struct LambdaClockTests {
2127
@@ -108,4 +114,26 @@ struct LambdaClockTests {
108114 #expect( remainingTime < . zero)
109115 #expect( remainingTime <= . seconds( - 29 ) ) // Allow some timing tolerance
110116 }
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+ }
111139}
You can’t perform that action at this time.
0 commit comments