From 3ab7b1437d5297975412fb5e67f5a9d7c7428846 Mon Sep 17 00:00:00 2001 From: Sebastien Stormacq Date: Sun, 24 Aug 2025 13:19:18 +0200 Subject: [PATCH 1/2] fix: deadline header with correct instant value (#551) --- Sources/AWSLambdaRuntime/LambdaClock.swift | 7 ++++++- Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Sources/AWSLambdaRuntime/LambdaClock.swift b/Sources/AWSLambdaRuntime/LambdaClock.swift index 6f3df393..53b641cc 100644 --- a/Sources/AWSLambdaRuntime/LambdaClock.swift +++ b/Sources/AWSLambdaRuntime/LambdaClock.swift @@ -62,7 +62,7 @@ public struct LambdaClock: Clock { /// ## Thread Safety /// /// `Instant` is a value type and is inherently thread-safe. - public struct Instant: InstantProtocol { + public struct Instant: InstantProtocol, CustomStringConvertible { /// The number of milliseconds since the Unix epoch. let instant: Int64 @@ -122,6 +122,11 @@ public struct LambdaClock: Clock { public init(millisecondsSinceEpoch milliseconds: Int64) { self.instant = milliseconds } + + /// Renders an Instant as an EPOCH value + public var description: String { + "\(self.instant)" + } } /// The current instant according to this clock. diff --git a/Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift b/Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift index 413a3aa2..31e4d190 100644 --- a/Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift +++ b/Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift @@ -136,4 +136,12 @@ struct LambdaClockTests { "LambdaClock and Foundation Date should be within 10ms of each other, difference was \(difference)ms" ) } + @Test("Instant renders as string with an epoch number") + func instantRendersAsStringWithEpochNumber() { + let clock = LambdaClock() + let instant = clock.now + + let expectedString = "\(instant)" + #expect(expectedString.allSatisfy { $0.isNumber }, "String should only contain numbers") + } } From dbcee4468c45ee5d507e91e7318547f172ba7453 Mon Sep 17 00:00:00 2001 From: Sebastien Stormacq Date: Sun, 24 Aug 2025 13:28:29 +0200 Subject: [PATCH 2/2] make test more robust --- Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift b/Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift index 31e4d190..b1d6f974 100644 --- a/Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift +++ b/Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift @@ -143,5 +143,12 @@ struct LambdaClockTests { let expectedString = "\(instant)" #expect(expectedString.allSatisfy { $0.isNumber }, "String should only contain numbers") + + if let expectedNumber = Int64(expectedString) { + let newInstant = LambdaClock.Instant(millisecondsSinceEpoch: expectedNumber) + #expect(instant == newInstant, "Instant should match the expected number") + } else { + Issue.record("expectedString is not a number") + } } }