Skip to content

Commit

Permalink
RUMM-2334 Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxep committed Oct 14, 2022
1 parent b4c46e8 commit e7cbfcb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,47 @@ class DatadogContextProviderTests: XCTestCase {
XCTAssertEqual(context.carrierInfo, carrierInfo)
}

func testPublishNewContextOnValueChange() throws {
let expectation = self.expectation(description: "publish new context")
expectation.expectedFulfillmentCount = 3

// Given
let serverOffsetPublisher = ContextValuePublisherMock<TimeInterval>(initialValue: 0)

let provider = DatadogContextProvider(context: context)
provider.subscribe(\.serverTimeOffset, to: serverOffsetPublisher)

provider.publish { _ in
expectation.fulfill()
}

// When
(0..<expectation.expectedFulfillmentCount).forEach { _ in
serverOffsetPublisher.value = .mockRandomInThePast()
}

wait(for: [expectation], timeout: 0.5)
}

func testPublishContextOnContextRead() throws {
let expectation = self.expectation(description: "publish new context")
expectation.expectedFulfillmentCount = 3

// Given

let provider = DatadogContextProvider(context: context)
provider.publish { _ in
expectation.fulfill()
}

// When
(0..<expectation.expectedFulfillmentCount).forEach { _ in
_ = provider.read()
}

wait(for: [expectation], timeout: 0.5)
}

// MARK: - Thread Safety

func testThreadSafety() {
Expand Down
19 changes: 0 additions & 19 deletions Tests/DatadogTests/Datadog/TracerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -683,25 +683,6 @@ class TracerTests: XCTestCase {
XCTAssertValidRumUUID(try spanMatcher.meta.custom(keyPath: "meta.\(RUMMonitor.Attributes.viewID)"))
}

func testGivenBundlingWithRUMEnabledButRUMMonitorNotRegistered_whenSendingSpan_itPrintsWarning() throws {
let tracing: TracingFeature = .mockByRecordingSpanMatchers()
core.register(feature: tracing)

// given
Global.sharedTracer = Tracer.initialize(configuration: .init(), in: core).dd
defer { Global.sharedTracer = DDNoopTracer() }

// when
let span = Global.sharedTracer.startSpan(operationName: "operation", tags: [:], startTime: Date())
span.finish()

// then
let spanMatcher = try tracing.waitAndReturnSpanMatchers(count: 1)[0]
XCTAssertNil(try? spanMatcher.meta.custom(keyPath: "meta.\(RUMMonitor.Attributes.applicationID)"))
XCTAssertNil(try? spanMatcher.meta.custom(keyPath: "meta.\(RUMMonitor.Attributes.sessionID)"))
XCTAssertNil(try? spanMatcher.meta.custom(keyPath: "meta.\(RUMMonitor.Attributes.viewID)"))
}

// MARK: - Injecting span context into carrier

func testItInjectsSpanContextWithHTTPHeadersWriter() {
Expand Down

0 comments on commit e7cbfcb

Please sign in to comment.