Skip to content

Commit bafb98b

Browse files
authored
Added tests to uploadTask instrumentation (#889)
* Added tests to uploadTask instrumentation * Fixing tests * Modified makefile to use latest os * Bumped to Xcode 16.4 * Rollback makefile changes - changed version * Fix visionOS version * Added suggestions * Rollback: using visionOS 2.5
1 parent 59ef505 commit bafb98b

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

.github/workflows/BuildAndTest.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
runs-on: macos-15
3030
steps:
3131
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
32+
- uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
33+
with:
34+
xcode-version: latest-stable
3235
- name: Build and Test for macOS
3336
run: swift test --enable-code-coverage
3437
- name: Upload Code coverage
@@ -41,6 +44,9 @@ jobs:
4144
runs-on: macos-15
4245
steps:
4346
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
47+
- uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
48+
with:
49+
xcode-version: latest-stable
4450
- name: Install Homebrew kegs
4551
run: make setup-brew
4652
- name: Build for iOS
@@ -51,6 +57,9 @@ jobs:
5157
runs-on: macos-15
5258
steps:
5359
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
60+
- uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
61+
with:
62+
xcode-version: latest-stable
5463
- name: Install Homebrew kegs
5564
run: make setup-brew
5665
- name: Build for tvOS
@@ -61,6 +70,9 @@ jobs:
6170
runs-on: macos-15
6271
steps:
6372
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
73+
- uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
74+
with:
75+
xcode-version: latest-stable
6476
- name: Install Homebrew kegs
6577
run: make setup-brew
6678
- name: Build for watchOS
@@ -71,6 +83,9 @@ jobs:
7183
runs-on: macos-15
7284
steps:
7385
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
86+
- uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
87+
with:
88+
xcode-version: latest-stable
7489
- name: Install Homebrew kegs
7590
run: make setup-brew
7691
- name: Build for visionOS

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@ PROJECT_NAME="opentelemetry-swift-Package"
22

33
XCODEBUILD_OPTIONS_IOS=\
44
-configuration Debug \
5-
-destination platform='iOS Simulator,name=iPhone 16,OS=18.0' \
5+
-destination 'platform=iOS Simulator,name=iPhone 16' \
66
-scheme $(PROJECT_NAME) \
77
-test-iterations 5 \
88
-retry-tests-on-failure \
99
-workspace .
1010

1111
XCODEBUILD_OPTIONS_TVOS=\
1212
-configuration Debug \
13-
-destination platform='tvOS Simulator,name=Apple TV 4K (3rd generation),OS=18.0' \
13+
-destination 'platform=tvOS Simulator,name=Apple TV 4K (3rd generation)' \
1414
-scheme $(PROJECT_NAME) \
1515
-test-iterations 5 \
1616
-retry-tests-on-failure \
1717
-workspace .
1818

1919
XCODEBUILD_OPTIONS_WATCHOS=\
2020
-configuration Debug \
21-
-destination platform='watchOS Simulator,name=Apple Watch Series 10 (46mm),OS=11.0' \
21+
-destination 'platform=watchOS Simulator,name=Apple Watch Series 10 (46mm)' \
2222
-scheme $(PROJECT_NAME) \
2323
-test-iterations 5 \
2424
-retry-tests-on-failure \
2525
-workspace .
2626

2727
XCODEBUILD_OPTIONS_VISIONOS=\
2828
-configuration Debug \
29-
-destination platform='visionOS Simulator,name=Apple Vision Pro,OS=2.0' \
29+
-destination 'platform=visionOS Simulator,name=Apple Vision Pro,OS=2.5' \
3030
-scheme $(PROJECT_NAME) \
3131
-test-iterations 5 \
3232
-retry-tests-on-failure \

Tests/InstrumentationTests/URLSessionTests/URLSessionInstrumentationTests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,41 @@ class URLSessionInstrumentationTests: XCTestCase {
417417
XCTAssertNotNil(URLSessionInstrumentationTests.requestCopy?.allHTTPHeaderFields?[W3CTraceContextPropagator.traceparent])
418418
}
419419

420+
public func testUploadTaskWithUrlBlock() {
421+
let url = URL(string: "http://localhost:33333/success")!
422+
var request = URLRequest(url: url)
423+
request.httpMethod = "POST"
424+
425+
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: sessionDelegate, delegateQueue: nil)
426+
let task = session.uploadTask(
427+
with: request,
428+
from: "UploadData".data(using: .utf8)!
429+
)
430+
task.resume()
431+
URLSessionInstrumentationTests.semaphore.wait()
432+
433+
XCTAssertTrue(URLSessionInstrumentationTests.checker.createdRequestCalled)
434+
XCTAssertTrue(URLSessionInstrumentationTests.checker.receivedResponseCalled)
435+
436+
XCTAssertNotNil(URLSessionInstrumentationTests.requestCopy?.allHTTPHeaderFields?[W3CTraceContextPropagator.traceparent])
437+
}
438+
439+
public func testUploadFileTaskWithUrlBlock() {
440+
let url = URL(string: "http://localhost:33333/success")!
441+
var request = URLRequest(url: url)
442+
request.httpMethod = "POST"
443+
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: sessionDelegate, delegateQueue: nil)
444+
445+
let task = session.uploadTask(with: URLRequest(url: url), fromFile: url)
446+
task.resume()
447+
URLSessionInstrumentationTests.semaphore.wait()
448+
449+
XCTAssertTrue(URLSessionInstrumentationTests.checker.createdRequestCalled)
450+
XCTAssertTrue(URLSessionInstrumentationTests.checker.receivedResponseCalled)
451+
452+
XCTAssertNotNil(URLSessionInstrumentationTests.requestCopy?.allHTTPHeaderFields?[W3CTraceContextPropagator.traceparent])
453+
}
454+
420455
public func testDownloadTaskWithRequestBlock() {
421456
let url = URL(string: "http://localhost:33333/success")!
422457
let request = URLRequest(url: url)

0 commit comments

Comments
 (0)