From 3d746ed1582bf06f486ba09f42d677ed49bedcfe Mon Sep 17 00:00:00 2001 From: Maxime Epain Date: Tue, 5 Apr 2022 16:03:03 +0200 Subject: [PATCH] RUMM-2079 `time_spent` can't be lower than 1ns --- Sources/Datadog/RUM/RUMMonitor/Scopes/RUMViewScope.swift | 4 ++-- .../Datadog/RUM/RUMMonitor/Scopes/RUMViewScopeTests.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Datadog/RUM/RUMMonitor/Scopes/RUMViewScope.swift b/Sources/Datadog/RUM/RUMMonitor/Scopes/RUMViewScope.swift index 93680472a8..224a37a569 100644 --- a/Sources/Datadog/RUM/RUMMonitor/Scopes/RUMViewScope.swift +++ b/Sources/Datadog/RUM/RUMMonitor/Scopes/RUMViewScope.swift @@ -368,8 +368,8 @@ internal class RUMViewScope: RUMScope, RUMContextProvider { // RUMM-1779 Keep view active as long as we have ongoing resources let isActive = isActiveView || !resourceScopes.isEmpty - - let timeSpent = command.time.timeIntervalSince(viewStartTime) + // RUMM-2079 `time_spent` can't be lower than 1ns + let timeSpent = max(1e-9, command.time.timeIntervalSince(viewStartTime)) let cpuInfo = vitalInfoSampler.cpu let memoryInfo = vitalInfoSampler.memory let refreshRateInfo = vitalInfoSampler.refreshRate diff --git a/Tests/DatadogTests/Datadog/RUM/RUMMonitor/Scopes/RUMViewScopeTests.swift b/Tests/DatadogTests/Datadog/RUM/RUMMonitor/Scopes/RUMViewScopeTests.swift index 8834c3f72e..2a615efd15 100644 --- a/Tests/DatadogTests/Datadog/RUM/RUMMonitor/Scopes/RUMViewScopeTests.swift +++ b/Tests/DatadogTests/Datadog/RUM/RUMMonitor/Scopes/RUMViewScopeTests.swift @@ -154,7 +154,7 @@ class RUMViewScopeTests: XCTestCase { XCTAssertEqual(event.view.name, "ViewName") let viewIsActive = try XCTUnwrap(event.view.isActive) XCTAssertTrue(viewIsActive) - XCTAssertEqual(event.view.timeSpent, 0) + XCTAssertEqual(event.view.timeSpent, 1) // Minimum `time_spent of 1 nanosecond XCTAssertEqual(event.view.action.count, 1, "The initial view update must have come with `application_start` action sent.") XCTAssertEqual(event.view.error.count, 0) XCTAssertEqual(event.view.resource.count, 0) @@ -195,7 +195,7 @@ class RUMViewScopeTests: XCTestCase { XCTAssertEqual(event.view.name, "ViewName") let viewIsActive = try XCTUnwrap(event.view.isActive) XCTAssertTrue(viewIsActive) - XCTAssertEqual(event.view.timeSpent, 0) + XCTAssertEqual(event.view.timeSpent, 1) // Minimum `time_spent of 1 nanosecond XCTAssertEqual(event.view.action.count, isInitialView ? 1 : 0, "It must track application start action only if this is an initial view") XCTAssertEqual(event.view.error.count, 0) XCTAssertEqual(event.view.resource.count, 0)