@@ -54,9 +54,6 @@ final class TracerTests: XCTestCase {
5454 }
5555
5656 func testWithSpan_success( ) {
57- guard #available( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * ) else {
58- return
59- }
6057 let tracer = TestTracer ( )
6158
6259 var spanEnded = false
@@ -91,10 +88,6 @@ final class TracerTests: XCTestCase {
9188 }
9289
9390 func testWithSpan_automaticBaggagePropagation_sync( ) throws {
94- guard #available( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * ) else {
95- throw XCTSkip ( " Task locals are not supported on this platform. " )
96- }
97-
9891 let tracer = TestTracer ( )
9992
10093 var spanEnded = false
@@ -114,10 +107,6 @@ final class TracerTests: XCTestCase {
114107 }
115108
116109 func testWithSpan_automaticBaggagePropagation_sync_throws( ) throws {
117- guard #available( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * ) else {
118- throw XCTSkip ( " Task locals are not supported on this platform. " )
119- }
120-
121110 let tracer = TestTracer ( )
122111
123112 var spanEnded = false
@@ -137,11 +126,7 @@ final class TracerTests: XCTestCase {
137126 XCTFail ( " Should have thrown " )
138127 }
139128
140- func testWithSpan_automaticBaggagePropagation_async( ) throws {
141- guard #available( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * ) else {
142- throw XCTSkip ( " Task locals are not supported on this platform. " )
143- }
144-
129+ func testWithSpan_automaticBaggagePropagation_async( ) async throws {
145130 let tracer = TestTracer ( )
146131
147132 let spanEnded : LockedValueBox < Bool > = . init( false )
@@ -151,22 +136,16 @@ final class TracerTests: XCTestCase {
151136 " world "
152137 }
153138
154- try self . testAsync {
155- let value = try await tracer. withAnySpan ( " hello " ) { ( span: any Tracing . Span ) -> String in
156- XCTAssertEqual ( span. context. traceID, ServiceContext . current? . traceID)
157- return try await operation ( span)
158- }
159-
160- XCTAssertEqual ( value, " world " )
161- XCTAssertTrue ( spanEnded. withValue { $0 } )
139+ let value = try await tracer. withAnySpan ( " hello " ) { ( span: any Tracing . Span ) -> String in
140+ XCTAssertEqual ( span. context. traceID, ServiceContext . current? . traceID)
141+ return try await operation ( span)
162142 }
163- }
164143
165- func testWithSpan_enterFromNonAsyncCode_passBaggage_asyncOperation( ) throws {
166- guard #available( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * ) else {
167- throw XCTSkip ( " Task locals are not supported on this platform. " )
168- }
144+ XCTAssertEqual ( value, " world " )
145+ XCTAssertTrue ( spanEnded. withValue { $0 } )
146+ }
169147
148+ func testWithSpan_enterFromNonAsyncCode_passBaggage_asyncOperation( ) async throws {
170149 let tracer = TestTracer ( )
171150
172151 let spanEnded : LockedValueBox < Bool > = . init( false )
@@ -176,26 +155,20 @@ final class TracerTests: XCTestCase {
176155 " world "
177156 }
178157
179- self . testAsync {
180- var fromNonAsyncWorld = ServiceContext . topLevel
181- fromNonAsyncWorld. traceID = " 1234-5678 "
182- let value = await tracer. withAnySpan ( " hello " , context: fromNonAsyncWorld) {
183- ( span: any Tracing . Span ) -> String in
184- XCTAssertEqual ( span. context. traceID, ServiceContext . current? . traceID)
185- XCTAssertEqual ( span. context. traceID, fromNonAsyncWorld. traceID)
186- return await operation ( span)
187- }
188-
189- XCTAssertEqual ( value, " world " )
190- XCTAssertTrue ( spanEnded. withValue { $0 } )
158+ var fromNonAsyncWorld = ServiceContext . topLevel
159+ fromNonAsyncWorld. traceID = " 1234-5678 "
160+ let value = await tracer. withAnySpan ( " hello " , context: fromNonAsyncWorld) {
161+ ( span: any Tracing . Span ) -> String in
162+ XCTAssertEqual ( span. context. traceID, ServiceContext . current? . traceID)
163+ XCTAssertEqual ( span. context. traceID, fromNonAsyncWorld. traceID)
164+ return await operation ( span)
191165 }
192- }
193166
194- func testWithSpan_automaticBaggagePropagation_async_throws( ) throws {
195- guard #available( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * ) else {
196- throw XCTSkip ( " Task locals are not supported on this platform. " )
197- }
167+ XCTAssertEqual ( value, " world " )
168+ XCTAssertTrue ( spanEnded. withValue { $0 } )
169+ }
198170
171+ func testWithSpan_automaticBaggagePropagation_async_throws( ) async throws {
199172 let tracer = TestTracer ( )
200173
201174 let spanEnded : LockedValueBox < Bool > = . init( false )
@@ -205,23 +178,17 @@ final class TracerTests: XCTestCase {
205178 throw ExampleSpanError ( )
206179 }
207180
208- self . testAsync {
209- do {
210- _ = try await tracer. withAnySpan ( " hello " , operation)
211- } catch {
212- XCTAssertTrue ( spanEnded. withValue { $0 } )
213- XCTAssertEqual ( error as? ExampleSpanError , ExampleSpanError ( ) )
214- return
215- }
216- XCTFail ( " Should have thrown " )
181+ do {
182+ _ = try await tracer. withAnySpan ( " hello " , operation)
183+ } catch {
184+ XCTAssertTrue ( spanEnded. withValue { $0 } )
185+ XCTAssertEqual ( error as? ExampleSpanError , ExampleSpanError ( ) )
186+ return
217187 }
188+ XCTFail ( " Should have thrown " )
218189 }
219190
220- func test_static_Tracer_withSpan_automaticBaggagePropagation_async_throws( ) throws {
221- guard #available( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * ) else {
222- throw XCTSkip ( " Task locals are not supported on this platform. " )
223- }
224-
191+ func test_static_Tracer_withSpan_automaticBaggagePropagation_async_throws( ) async throws {
225192 let tracer = TestTracer ( )
226193
227194 let spanEnded : LockedValueBox < Bool > = . init( false )
@@ -231,23 +198,17 @@ final class TracerTests: XCTestCase {
231198 throw ExampleSpanError ( )
232199 }
233200
234- self . testAsync {
235- do {
236- _ = try await tracer. withSpan ( " hello " , operation)
237- } catch {
238- XCTAssertTrue ( spanEnded. withValue { $0 } )
239- XCTAssertEqual ( error as? ExampleSpanError , ExampleSpanError ( ) )
240- return
241- }
242- XCTFail ( " Should have thrown " )
201+ do {
202+ _ = try await tracer. withSpan ( " hello " , operation)
203+ } catch {
204+ XCTAssertTrue ( spanEnded. withValue { $0 } )
205+ XCTAssertEqual ( error as? ExampleSpanError , ExampleSpanError ( ) )
206+ return
243207 }
208+ XCTFail ( " Should have thrown " )
244209 }
245210
246- func test_static_Tracer_withSpan_automaticBaggagePropagation_throws( ) throws {
247- guard #available( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * ) else {
248- throw XCTSkip ( " Task locals are not supported on this platform. " )
249- }
250-
211+ func test_static_Tracer_withSpan_automaticBaggagePropagation_throws( ) async throws {
251212 let tracer = TestTracer ( )
252213
253214 let spanEnded : LockedValueBox < Bool > = . init( false )
@@ -257,23 +218,17 @@ final class TracerTests: XCTestCase {
257218 throw ExampleSpanError ( )
258219 }
259220
260- self . testAsync {
261- do {
262- _ = try await tracer. withSpan ( " hello " , operation)
263- } catch {
264- XCTAssertTrue ( spanEnded. withValue { $0 } )
265- XCTAssertEqual ( error as? ExampleSpanError , ExampleSpanError ( ) )
266- return
267- }
268- XCTFail ( " Should have thrown " )
221+ do {
222+ _ = try await tracer. withSpan ( " hello " , operation)
223+ } catch {
224+ XCTAssertTrue ( spanEnded. withValue { $0 } )
225+ XCTAssertEqual ( error as? ExampleSpanError , ExampleSpanError ( ) )
226+ return
269227 }
228+ XCTFail ( " Should have thrown " )
270229 }
271230
272231 func testWithSpan_recordErrorWithAttributes( ) throws {
273- guard #available( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * ) else {
274- throw XCTSkip ( " Task locals are not supported on this platform. " )
275- }
276-
277232 let tracer = TestTracer ( )
278233
279234 var endedSpan : TestSpan ?
@@ -318,23 +273,6 @@ final class TracerTests: XCTestCase {
318273 let span = tracer. spans. first!
319274 XCTAssertEqual ( span. startTimestampNanosSinceEpoch, instant. nanosecondsSinceEpoch)
320275 }
321-
322- // @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
323- /// Helper method to execute async operations until we can use async tests (currently incompatible with the generated LinuxMain file).
324- /// - Parameter operation: The operation to test.
325- func testAsync( _ operation: @Sendable @escaping ( ) async throws -> Void ) rethrows {
326- let group = DispatchGroup ( )
327- group. enter ( )
328- Task . detached {
329- do {
330- try await operation ( )
331- } catch {
332- throw error
333- }
334- group. leave ( )
335- }
336- group. wait ( )
337- }
338276}
339277
340278struct ExampleSpanError : Error , Equatable { }
0 commit comments