Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 0 additions & 94 deletions Tests/InstrumentationTests/InstrumentationSystemTests.swift

This file was deleted.

6 changes: 1 addition & 5 deletions Tests/TracingTests/ActorTracingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ import XCTest

@testable import Instrumentation

/// This is a compile-time test
final class ActorTracingTests: XCTestCase {
override class func tearDown() {
super.tearDown()
InstrumentationSystem.bootstrapInternal(nil)
}

func test() {}
}

Expand Down
31 changes: 8 additions & 23 deletions Tests/TracingTests/DynamicTracepointTracerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,9 @@ import XCTest
@testable import Instrumentation

final class DynamicTracepointTracerTests: XCTestCase {
override class func tearDown() {
super.tearDown()
InstrumentationSystem.bootstrapInternal(nil)
}

func test_adhoc_enableBySourceLoc() {
let tracer = DynamicTracepointTestTracer()

InstrumentationSystem.bootstrapInternal(tracer)
defer {
InstrumentationSystem.bootstrapInternal(NoOpTracer())
}

let fileID = #fileID
let fakeLine: UInt = 77 // trick number, see withSpan below.
let fakeNextLine: UInt = fakeLine + 11
Expand Down Expand Up @@ -71,19 +61,14 @@ final class DynamicTracepointTracerTests: XCTestCase {
func test_adhoc_enableByFunction() {
let tracer = DynamicTracepointTestTracer()

InstrumentationSystem.bootstrapInternal(tracer)
defer {
InstrumentationSystem.bootstrapInternal(NoOpTracer())
}

let fileID = #fileID
tracer.enableTracepoint(function: "traceMeLogic(fakeLine:)")
tracer.enableTracepoint(function: "traceMeLogic(fakeLine:tracer:)")

let fakeLine: UInt = 66
let fakeNextLine: UInt = fakeLine + 11

self.logic(fakeLine: 55)
self.traceMeLogic(fakeLine: fakeLine)
self.logic(fakeLine: 55, tracer: tracer)
self.traceMeLogic(fakeLine: fakeLine, tracer: tracer)

XCTAssertEqual(tracer.spans.count, 2)
for span in tracer.spans {
Expand All @@ -93,15 +78,15 @@ final class DynamicTracepointTracerTests: XCTestCase {
XCTAssertEqual(tracer.spans[1].context.spanID, "span-id-fake-\(fileID)-\(fakeNextLine)")
}

func logic(fakeLine: UInt) {
InstrumentationSystem.tracer.withSpan("\(#function)-dont", line: fakeLine) { _ in
func logic(fakeLine: UInt, tracer: any Tracer) {
tracer.withSpan("\(#function)-dont", line: fakeLine) { _ in
// inside
}
}

func traceMeLogic(fakeLine: UInt) {
InstrumentationSystem.tracer.withSpan("\(#function)-yes", line: fakeLine) { _ in
InstrumentationSystem.tracer.withSpan("\(#function)-yes-inside", line: fakeLine + 11) { _ in
func traceMeLogic(fakeLine: UInt, tracer: any Tracer) {
tracer.withSpan("\(#function)-yes", line: fakeLine) { _ in
tracer.withSpan("\(#function)-yes-inside", line: fakeLine + 11) { _ in
// inside
}
}
Expand Down
11 changes: 4 additions & 7 deletions Tests/TracingTests/SpanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ final class SpanTests: XCTestCase {
}

func testSpanAttributeIsExpressibleByArrayLiteral() {
let s = InstrumentationSystem.legacyTracer.startAnySpan("", context: .topLevel)
let tracer = TestTracer()
let s = tracer.startAnySpan("", context: .topLevel)
s.attributes["hi"] = [42, 21]
s.attributes["hi"] = [42.10, 21.0]
s.attributes["hi"] = [true, false]
Expand All @@ -91,12 +92,8 @@ final class SpanTests: XCTestCase {
}

func testSpanAttributeSetEntireCollection() {
InstrumentationSystem.bootstrapInternal(TestTracer())
defer {
InstrumentationSystem.bootstrapInternal(NoOpTracer())
}

let s = InstrumentationSystem.legacyTracer.startAnySpan("", context: .topLevel)
let tracer = TestTracer()
let s = tracer.startAnySpan("", context: .topLevel)
var attrs = s.attributes
attrs["one"] = 42
attrs["two"] = [1, 2, 34]
Expand Down
2 changes: 1 addition & 1 deletion Tests/TracingTests/TestTracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ extension ServiceContext {

/// Only intended to be used in single-threaded testing.
final class TestSpan: Span {
private let kind: SpanKind
let kind: SpanKind

private var status: SpanStatus?

Expand Down
8 changes: 4 additions & 4 deletions Tests/TracingTests/TracedLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ final class TracedLock: @unchecked Sendable {
self.underlyingLock = NSLock()
}

func lock(context: ServiceContext) {
func lock(context: ServiceContext, tracer: any Tracer) {
// time here
self.underlyingLock.lock()
self.activeSpan = InstrumentationSystem.legacyTracer.startAnySpan(self.name, context: context)
self.activeSpan = tracer.startSpan(self.name, context: context)
}

func unlock(context: ServiceContext) {
Expand All @@ -42,8 +42,8 @@ final class TracedLock: @unchecked Sendable {
self.underlyingLock.unlock()
}

func withLock(context: ServiceContext, _ closure: () -> Void) {
self.lock(context: context)
func withLock(context: ServiceContext, tracer: any Tracer, _ closure: () -> Void) {
self.lock(context: context, tracer: tracer)
defer { self.unlock(context: context) }
closure()
}
Expand Down
9 changes: 1 addition & 8 deletions Tests/TracingTests/TracedLockTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,16 @@ import XCTest
@testable import Instrumentation

final class TracedLockTests: XCTestCase {
override class func tearDown() {
super.tearDown()
InstrumentationSystem.bootstrapInternal(nil)
}

func test_tracesLockedTime() {
let tracer = TracedLockPrintlnTracer()
InstrumentationSystem.bootstrapInternal(tracer)

let lock = TracedLock(name: "my-cool-lock")

func launchTask(_ name: String) {
DispatchQueue.global().async {
var context = ServiceContext.topLevel
context[TaskIDKey.self] = name

lock.lock(context: context)
lock.lock(context: context, tracer: tracer)
lock.unlock(context: context)
}
}
Expand Down
Loading