From 0124d9ad5c0e75e1c2b9b56d4cc53e3da3a65ebe Mon Sep 17 00:00:00 2001 From: hamzahrmalik Date: Wed, 15 May 2024 06:36:25 +0100 Subject: [PATCH] Change Timer.record(duration: Duration) signature to avoid source breakage (#144) --- Sources/Metrics/Metrics.swift | 4 +--- Tests/MetricsTests/MetricsTests.swift | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Sources/Metrics/Metrics.swift b/Sources/Metrics/Metrics.swift index d3da910..42fcbc6 100644 --- a/Sources/Metrics/Metrics.swift +++ b/Sources/Metrics/Metrics.swift @@ -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) diff --git a/Tests/MetricsTests/MetricsTests.swift b/Tests/MetricsTests/MetricsTests.swift index de2bac9..49b5f7b 100644 --- a/Tests/MetricsTests/MetricsTests.swift +++ b/Tests/MetricsTests/MetricsTests.swift @@ -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")