Skip to content

Commit 7f4bd97

Browse files
author
Nacho Bonafonte
committed
When adding support for watchOS some tests were wrongly skipped for all platforms, skip them properly now only for watchOS
1 parent 2d7f897 commit 7f4bd97

File tree

9 files changed

+65
-62
lines changed

9 files changed

+65
-62
lines changed

Tests/ExportersTests/DatadogExporter/DatadogExporterTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class DatadogExporterTests: XCTestCase {
1818
}
1919

2020
func testWhenExportSpanIsCalled_thenTraceAndLogsAreUploaded() throws {
21-
if #available(watchOS 3.0, *) {
22-
throw XCTSkip("Test is flaky on watchOS")
23-
}
21+
#if os(watchOS)
22+
throw XCTSkip("Test is flaky on watchOS")
23+
#endif
2424

2525
var logsSent = false
2626
var tracesSent = false
@@ -99,9 +99,9 @@ class DatadogExporterTests: XCTestCase {
9999
}
100100

101101
func testWhenExportMetricIsCalled_thenMetricsAreUploaded() throws {
102-
if #available(watchOS 3.0, *) {
103-
throw XCTSkip("Test is flaky on watchOS")
104-
}
102+
#if os(watchOS)
103+
throw XCTSkip("Test is flaky on watchOS")
104+
#endif
105105

106106
var metricsSent = false
107107
let expecMetrics = expectation(description: "metrics received")

Tests/ExportersTests/DatadogExporter/Logs/LogsExporterTests.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@ class LogsExporterTests: XCTestCase {
1818
}
1919

2020
func testWhenExportSpanIsCalledAndSpanHasEvent_thenLogIsUploaded() throws {
21-
if #available(watchOS 3.0, *) {
22-
throw XCTSkip("Test is flaky on watchOS")
23-
}
24-
21+
#if os(watchOS)
22+
throw XCTSkip("Test is flaky on watchOS")
23+
#endif
2524
var logsSent = false
2625
let expec = expectation(description: "logs received")
2726
let server = HttpTestServer(url: URL(string: "http://localhost:33333"),
2827
config: HttpTestServerConfig(tracesReceivedCallback: nil,
2928
logsReceivedCallback: {
3029
logsSent = true
3130
expec.fulfill()
32-
}))
31+
}))
3332

3433
let sem = DispatchSemaphore(value: 0)
3534
DispatchQueue.global(qos: .default).async {
@@ -81,7 +80,7 @@ class LogsExporterTests: XCTestCase {
8180
name: "spanName",
8281
kind: .server,
8382
startTime: Date(timeIntervalSinceReferenceDate: 3000),
84-
events: [SpanData.Event(name: "event", timestamp: Date(), attributes:["attributeKey": AttributeValue.string("attributeValue")])],
83+
events: [SpanData.Event(name: "event", timestamp: Date(), attributes: ["attributeKey": AttributeValue.string("attributeValue")])],
8584
endTime: Date(timeIntervalSinceReferenceDate: 3001),
8685
hasRemoteParent: false)
8786
}

Tests/ExportersTests/DatadogExporter/Spans/SpansExporterTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ class SpansExporterTests: XCTestCase {
1818
}
1919

2020
func testWhenExportSpanIsCalled_thenTraceIsUploaded() throws {
21-
if #available(watchOS 3.0, *) {
22-
throw XCTSkip("Test is flaky on watchOS")
23-
}
21+
#if os(watchOS)
22+
throw XCTSkip("Test is flaky on watchOS")
23+
#endif
2424

2525
var tracesSent = false
2626
let expec = expectation(description: "traces received")
2727
let server = HttpTestServer(url: URL(string: "http://localhost:33333"),
2828
config: HttpTestServerConfig(tracesReceivedCallback: {
29-
tracesSent = true
30-
expec.fulfill()
31-
},
29+
tracesSent = true
30+
expec.fulfill()
31+
},
3232
logsReceivedCallback: nil))
3333
let sem = DispatchSemaphore(value: 0)
3434
DispatchQueue.global(qos: .default).async {

Tests/ExportersTests/DatadogExporter/Upload/DataUploadWorkerTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class DataUploadWorkerTests: XCTestCase {
3737
// MARK: - Data Uploads
3838

3939
func testItUploadsAllData() throws {
40-
if #available(watchOS 3.0, *) {
41-
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
42-
}
40+
#if os(watchOS)
41+
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
42+
#endif
4343

4444
let server = ServerMock(delivery: .success(response: .mockResponseWith(statusCode: 200)))
4545
let dataUploader = DataUploader(
@@ -159,9 +159,9 @@ class DataUploadWorkerTests: XCTestCase {
159159
}
160160

161161
func testWhenBatchFails_thenIntervalIncreases() throws {
162-
if #available(watchOS 3.0, *) {
163-
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
164-
}
162+
#if os(watchOS)
163+
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
164+
#endif
165165

166166
let delayChangeExpectation = expectation(description: "Upload delay is increased")
167167
let mockDelay = MockDelay { command in
@@ -195,9 +195,9 @@ class DataUploadWorkerTests: XCTestCase {
195195
}
196196

197197
func testWhenBatchSucceeds_thenIntervalDecreases() throws {
198-
if #available(watchOS 3.0, *) {
199-
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
200-
}
198+
#if os(watchOS)
199+
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
200+
#endif
201201

202202
let delayChangeExpectation = expectation(description: "Upload delay is decreased")
203203
let mockDelay = MockDelay { command in
@@ -257,9 +257,9 @@ class DataUploadWorkerTests: XCTestCase {
257257
}
258258

259259
func testItFlushesAllData() throws {
260-
if #available(watchOS 3.0, *) {
261-
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
262-
}
260+
#if os(watchOS)
261+
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
262+
#endif
263263

264264
let server = ServerMock(delivery: .success(response: .mockResponseWith(statusCode: 200)))
265265
let dataUploader = DataUploader(

Tests/ExportersTests/DatadogExporter/Upload/DataUploaderTests.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ extension DataUploadStatus: EquatableInTests {}
1010

1111
class DataUploaderTests: XCTestCase {
1212
func testWhenUploadCompletesWithSuccess_itReturnsExpectedUploadStatus() throws {
13-
if #available(watchOS 3.0, *) {
14-
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
15-
}
16-
13+
#if os(watchOS)
14+
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
15+
#endif
1716
// Given
1817
let randomResponse: HTTPURLResponse = .mockResponseWith(statusCode: (100 ... 599).randomElement()!)
1918
let randomRequestIDOrNil: String? = Bool.random() ? .mockRandom() : nil
@@ -38,9 +37,9 @@ class DataUploaderTests: XCTestCase {
3837
}
3938

4039
func testWhenUploadCompletesWithFailure_itReturnsExpectedUploadStatus() throws {
41-
if #available(watchOS 3.0, *) {
42-
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
43-
}
40+
#if os(watchOS)
41+
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
42+
#endif
4443

4544
// Given
4645
let randomErrorDescription: String = .mockRandom()

Tests/ExportersTests/DatadogExporter/Upload/HTTPClientTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class HTTPClientTests: XCTestCase {
2727
}
2828

2929
func testWhenRequestIsNotDelivered_itReturnsHTTPRequestDeliveryError() throws {
30-
if #available(watchOS 3.0, *) {
31-
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
32-
}
30+
#if os(watchOS)
31+
throw XCTSkip("Implementation needs to be updated for watchOS to make this test pass")
32+
#endif
3333

3434
let mockError = NSError(domain: "network", code: 999, userInfo: [NSLocalizedDescriptionKey: "no internet connection"])
3535
let server = ServerMock(delivery: .failure(error: mockError))

Tests/InstrumentationTests/URLSessionTests/Utils/HttpTestServer.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ internal class HttpTestServer {
9797
_ = channel.writeAndFlush(endpart).flatMap {
9898
channel.close()
9999
}
100+
break
100101
} else if request.uri.unicodeScalars.starts(with: "/forbidden".unicodeScalars) {
101102
let channel = context.channel
102103

@@ -111,14 +112,17 @@ internal class HttpTestServer {
111112
_ = channel.writeAndFlush(endpart).flatMap {
112113
channel.close()
113114
}
115+
break
114116
} else if request.uri.unicodeScalars.starts(with: "/error".unicodeScalars) {
115117
let channel = context.channel
116118
config?.errorCallback?()
117119
_ = channel.close()
120+
break
118121
}
119122
case .body:
120123
break
121-
case .end: break
124+
case .end:
125+
break
122126
}
123127
}
124128

Tests/OpenTelemetryApiTests/Context/ActivityContextManagerTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class ActivityContextManagerTests: XCTestCase {
226226
}
227227
span1.end()
228228
XCTAssert(OpenTelemetry.instance.contextProvider.activeSpan === nil)
229-
await waitForExpectations(timeout: 30)
229+
await fulfillment(of: [expec], timeout: 30)
230230
}
231231

232232
@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)
@@ -258,7 +258,7 @@ class ActivityContextManagerTests: XCTestCase {
258258
XCTAssert(OpenTelemetry.instance.contextProvider.activeSpan === span1)
259259
expec.fulfill()
260260
}
261-
await waitForExpectations(timeout: 30)
261+
await fulfillment(of: [expec], timeout: 30)
262262
span1.end()
263263
XCTAssert(OpenTelemetry.instance.contextProvider.activeSpan === nil)
264264
}
@@ -316,7 +316,8 @@ class ActivityContextManagerTests: XCTestCase {
316316
}
317317

318318
XCTAssert(ActivityContextManager.instance.getCurrentContextValue(forKey: .span) === parent)
319-
await waitForExpectations(timeout: 5, handler: nil)
319+
await fulfillment(of: [expectation1, expectation2], timeout: 30, enforceOrder: false)
320+
320321
parent.end()
321322
XCTAssert(OpenTelemetry.instance.contextProvider.activeSpan === nil)
322323
}

Tests/OpenTelemetrySdkTests/Metrics/CounterTests.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ final class CounterTests: XCTestCase {
2424
// We have ls1, ls2, ls3
2525
// ls1 and ls3 are not bound so they should removed when no usage for a Collect cycle.
2626
// ls2 is bound by user.
27-
testCounter.add( value: 100, labelset: ls1)
28-
testCounter.add( value: 10, labelset: ls1)
27+
testCounter.add(value: 100, labelset: ls1)
28+
testCounter.add(value: 10, labelset: ls1)
2929
// initial status for temp bound instruments are UpdatePending.
3030
XCTAssertEqual(RecordStatus.updatePending, testCounter.boundInstruments[ls1]?.status)
3131

3232
let boundCounterLabel2 = testCounter.bind(labelset: ls2)
33-
boundCounterLabel2.add( value: 200)
33+
boundCounterLabel2.add(value: 200)
3434
// initial/forever status for user bound instruments are Bound.
3535
XCTAssertEqual(RecordStatus.bound, testCounter.boundInstruments[ls2]?.status)
3636

37-
testCounter.add( value: 200, labelset: ls3)
38-
testCounter.add( value: 10, labelset: ls3)
37+
testCounter.add(value: 200, labelset: ls3)
38+
testCounter.add(value: 10, labelset: ls3)
3939
// initial status for temp bound instruments are UpdatePending.
4040
XCTAssertEqual(RecordStatus.updatePending, testCounter.boundInstruments[ls3]?.status)
4141

@@ -48,7 +48,7 @@ final class CounterTests: XCTestCase {
4848
XCTAssertEqual(RecordStatus.bound, testCounter.boundInstruments[ls2]?.status)
4949

5050
// Use ls1 again, so that it'll be promoted to UpdatePending
51-
testCounter.add( value: 100, labelset: ls1)
51+
testCounter.add(value: 100, labelset: ls1)
5252

5353
// This collect should mark ls1 as noPendingUpdate, leave ls2 untouched.
5454
// And ls3 as candidateForRemoval, as it was not used since last Collect
@@ -84,18 +84,18 @@ final class CounterTests: XCTestCase {
8484
// We have ls1, ls2, ls3
8585
// ls1 and ls3 are not bound so they should removed when no usage for a Collect cycle.
8686
// ls2 is bound by user.
87-
testCounter.add( value: 100.0, labelset: ls1)
88-
testCounter.add( value: 10.0, labelset: ls1)
87+
testCounter.add(value: 100.0, labelset: ls1)
88+
testCounter.add(value: 10.0, labelset: ls1)
8989
// initial status for temp bound instruments are UpdatePending.
9090
XCTAssertEqual(RecordStatus.updatePending, testCounter.boundInstruments[ls1]?.status)
9191

9292
let boundCounterLabel2 = testCounter.bind(labelset: ls2)
93-
boundCounterLabel2.add( value: 200.0)
93+
boundCounterLabel2.add(value: 200.0)
9494
// initial/forever status for user bound instruments are Bound.
9595
XCTAssertEqual(RecordStatus.bound, testCounter.boundInstruments[ls2]?.status)
9696

97-
testCounter.add( value: 200.0, labelset: ls3)
98-
testCounter.add( value: 10.0, labelset: ls3)
97+
testCounter.add(value: 200.0, labelset: ls3)
98+
testCounter.add(value: 10.0, labelset: ls3)
9999
// initial status for temp bound instruments are UpdatePending.
100100
XCTAssertEqual(RecordStatus.updatePending, testCounter.boundInstruments[ls3]?.status)
101101

@@ -108,7 +108,7 @@ final class CounterTests: XCTestCase {
108108
XCTAssertEqual(RecordStatus.bound, testCounter.boundInstruments[ls2]?.status)
109109

110110
// Use ls1 again, so that it'll be promoted to UpdatePending
111-
testCounter.add( value: 100.0, labelset: ls1)
111+
testCounter.add(value: 100.0, labelset: ls1)
112112

113113
// This collect should mark ls1 as noPendingUpdate, leave ls2 untouched.
114114
// And ls3 as candidateForRemoval, as it was not used since last Collect
@@ -130,9 +130,9 @@ final class CounterTests: XCTestCase {
130130
}
131131

132132
public func testIntCounterBoundInstrumentsStatusUpdatedCorrectlyMultiThread() throws {
133-
if #available(watchOS 3.0, *) {
134-
throw XCTSkip("Test is flaky on watchOS")
135-
}
133+
#if os(watchOS)
134+
throw XCTSkip("Test is flaky on watchOS")
135+
#endif
136136

137137
let testProcessor = TestMetricProcessor()
138138
let meter = MeterProviderSdk(metricProcessor: testProcessor, metricExporter: NoopMetricExporter()).get(instrumentationName: "scope1") as! MeterSdk
@@ -142,8 +142,8 @@ final class CounterTests: XCTestCase {
142142
let ls1 = meter.getLabelSet(labels: labels1)
143143

144144
// Call metric update with ls1 so that ls1 wont be brand new labelset when doing multi-thread test.
145-
testCounter.add( value: 100, labelset: ls1)
146-
testCounter.add( value: 10, labelset: ls1)
145+
testCounter.add(value: 100, labelset: ls1)
146+
testCounter.add(value: 10, labelset: ls1)
147147

148148
// This collect should mark ls1 NoPendingUpdate
149149
meter.collect()
@@ -163,7 +163,7 @@ final class CounterTests: XCTestCase {
163163
}
164164
DispatchQueue.global().async(group: mygroup) {
165165
for _ in 0 ..< 5 {
166-
testCounter.add( value: 100, labelset: ls1)
166+
testCounter.add(value: 100, labelset: ls1)
167167
}
168168
}
169169
mygroup.wait()

0 commit comments

Comments
 (0)