Skip to content

Commit 62ae211

Browse files
committed
add unit test for LambdaClock.now
1 parent d699f36 commit 62ae211

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff 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")
2026
struct 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
}

0 commit comments

Comments
 (0)