Skip to content

Commit

Permalink
Fixing tests for new atomic members
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelGHSeg committed Nov 27, 2024
1 parent 98974b2 commit 5f53cbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Sources/Segment/Utilities/Telemetry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Double> { _sampleRate }
private var flushTimer: Int = 30
internal var maxQueueSize: Int = 20
var errorLogSizeMax: Int = 4000
Expand All @@ -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<Bool> { _flushFirstError }
private var telemetryQueue = DispatchQueue(label: "telemetryQueue")
private var updateQueue = DispatchQueue(label: "updateQueue")
private var telemetryTimer: QueueTimer?
Expand Down
8 changes: 4 additions & 4 deletions Tests/Segment-Tests/Telemetry_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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)
Expand Down Expand Up @@ -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" }
Expand Down

0 comments on commit 5f53cbb

Please sign in to comment.