Skip to content

Commit 323b3f2

Browse files
authored
fix: Fix deadline header with correct instant value (#551) (#552)
Instant's value now correctly prints as an EPOCH number ### Motivation: A regression was introduced by #540. The HTTP headers returned by `LocalServer` contained an invalid representation of the Lamba Deadline. See #551 ### Modifications: - Add `CustomStringConvertible` to `LambdaClock.Instant` to just print the `Int64` value - add a unit test ### Result: The runtime works correctly with the new `LambdaClock`
1 parent 262c3b5 commit 323b3f2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Sources/AWSLambdaRuntime/LambdaClock.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public struct LambdaClock: Clock {
6262
/// ## Thread Safety
6363
///
6464
/// `Instant` is a value type and is inherently thread-safe.
65-
public struct Instant: InstantProtocol {
65+
public struct Instant: InstantProtocol, CustomStringConvertible {
6666
/// The number of milliseconds since the Unix epoch.
6767
let instant: Int64
6868

@@ -122,6 +122,11 @@ public struct LambdaClock: Clock {
122122
public init(millisecondsSinceEpoch milliseconds: Int64) {
123123
self.instant = milliseconds
124124
}
125+
126+
/// Renders an Instant as an EPOCH value
127+
public var description: String {
128+
"\(self.instant)"
129+
}
125130
}
126131

127132
/// The current instant according to this clock.

Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,19 @@ struct LambdaClockTests {
136136
"LambdaClock and Foundation Date should be within 10ms of each other, difference was \(difference)ms"
137137
)
138138
}
139+
@Test("Instant renders as string with an epoch number")
140+
func instantRendersAsStringWithEpochNumber() {
141+
let clock = LambdaClock()
142+
let instant = clock.now
143+
144+
let expectedString = "\(instant)"
145+
#expect(expectedString.allSatisfy { $0.isNumber }, "String should only contain numbers")
146+
147+
if let expectedNumber = Int64(expectedString) {
148+
let newInstant = LambdaClock.Instant(millisecondsSinceEpoch: expectedNumber)
149+
#expect(instant == newInstant, "Instant should match the expected number")
150+
} else {
151+
Issue.record("expectedString is not a number")
152+
}
153+
}
139154
}

0 commit comments

Comments
 (0)