diff --git a/Sources/Segment/Utilities/Telemetry.swift b/Sources/Segment/Utilities/Telemetry.swift index 6a07f8f..2198bc9 100644 --- a/Sources/Segment/Utilities/Telemetry.swift +++ b/Sources/Segment/Utilities/Telemetry.swift @@ -71,7 +71,8 @@ public class Telemetry: Subscriber { internal var session: any HTTPSession internal var host: String = HTTPClient.getDefaultAPIHost() - @Atomic var sampleRate: Double = 1.0 // inital sample rate should be 1.0, will be downsampled on start + @Atomic internal var sampleRate: Double = 1.0 // inital sample rate should be 1.0, will be downsampled on start + internal var sampleRateTest: Atomic { _sampleRate } private var flushTimer: Int = 30 internal var maxQueueSize: Int = 20 var errorLogSizeMax: Int = 4000 @@ -88,6 +89,7 @@ public class Telemetry: Subscriber { @Atomic internal var started = false @Atomic private var rateLimitEndTime: TimeInterval = 0 @Atomic internal var flushFirstError = true + internal var flushFirstErrorTest: Atomic { _flushFirstError } private var telemetryQueue = DispatchQueue(label: "telemetryQueue") private var updateQueue = DispatchQueue(label: "updateQueue") private var telemetryTimer: QueueTimer? diff --git a/Tests/Segment-Tests/Telemetry_Tests.swift b/Tests/Segment-Tests/Telemetry_Tests.swift index 44e6fae..e219ceb 100644 --- a/Tests/Segment-Tests/Telemetry_Tests.swift +++ b/Tests/Segment-Tests/Telemetry_Tests.swift @@ -12,7 +12,7 @@ class TelemetryTests: XCTestCase { self.errors.append("\(error)") } errors.removeAll() - Telemetry.shared.sampleRate = 1.0 + Telemetry.shared.sampleRateTest.set(1.0) mockTelemetryHTTPClient() } @@ -29,12 +29,12 @@ class TelemetryTests: XCTestCase { } func testTelemetryStart() { - Telemetry.shared.sampleRate = 0.0 + Telemetry.shared.sampleRateTest.set(0.0) Telemetry.shared.enable = true Telemetry.shared.start() XCTAssertFalse(Telemetry.shared.started) - Telemetry.shared.sampleRate = 1.0 + Telemetry.shared.sampleRateTest.set(1.0) Telemetry.shared.start() XCTAssertTrue(Telemetry.shared.started) XCTAssertTrue(errors.isEmpty) @@ -116,7 +116,7 @@ class TelemetryTests: XCTestCase { func testHTTPException() { mockTelemetryHTTPClient(shouldThrow: true) - Telemetry.shared.flushFirstError = true + Telemetry.shared.flushFirstErrorTest.set(true) Telemetry.shared.enable = true Telemetry.shared.start() Telemetry.shared.error(metric: Telemetry.INVOKE_METRIC, log: "log") { $0["error"] = "test" }