Change Timer.record(duration: Duration) signature to avoid source breakage (#144)
This commit is contained in:
parent
eb18581491
commit
0124d9ad5c
|
|
@ -82,11 +82,9 @@ extension Timer {
|
|||
///
|
||||
/// - Parameters:
|
||||
/// - duration: The `Duration` to record.
|
||||
///
|
||||
/// - Throws: `TimerError.durationToIntOverflow` if conversion from `Duration` to `Int64` of Nanoseconds overflowed.
|
||||
@available(macOS 13, iOS 16, tvOS 15, watchOS 8, *)
|
||||
@inlinable
|
||||
public func record(_ duration: Duration) {
|
||||
public func record(duration: Duration) {
|
||||
// `Duration` doesn't have a nice way to convert it nanoseconds or seconds,
|
||||
// and manual conversion can overflow.
|
||||
let seconds = duration.components.seconds.multipliedReportingOverflow(by: 1_000_000_000)
|
||||
|
|
|
|||
|
|
@ -111,11 +111,11 @@ class MetricsExtensionsTests: XCTestCase {
|
|||
|
||||
let duration = Duration(secondsComponent: 3, attosecondsComponent: 123_000_000_000_000_000)
|
||||
let nanoseconds = duration.components.seconds * 1_000_000_000 + duration.components.attoseconds / 1_000_000_000
|
||||
timer.record(duration)
|
||||
timer.record(duration: duration)
|
||||
|
||||
// Record a Duration that would overflow,
|
||||
// expect Int64.max to be recorded.
|
||||
timer.record(Duration(secondsComponent: 10_000_000_000, attosecondsComponent: 123))
|
||||
timer.record(duration: Duration(secondsComponent: 10_000_000_000, attosecondsComponent: 123))
|
||||
|
||||
let testTimer = try metrics.expectTimer(timer)
|
||||
XCTAssertEqual(testTimer.values.count, 2, "expected number of entries to match")
|
||||
|
|
|
|||
Loading…
Reference in New Issue