Skip to content

Commit 9970131

Browse files
authored
Fix flaky tests (#784)
This PR fixes 3 common source of failure for our test : 1. ~Deadlock : sometimes the test runner freeze and needs a total clean to be run. We fix this by removing the need to call the main thread in SegmentIntegration~ Moved to #784 2. Missing iOS simulator : Adding a command to list the simulators seems to magically fix the issue. 3. Flaky maxQueueSize test : I rewrote this one to be more stable We ran 21+ successful and consecutive test iterations : https://circleci.com/gh/segmentio/workflows/analytics-ios/tree/fix%2Fflaky-test Ref : LIB-543
1 parent 00c075a commit 9970131

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jobs:
66
xcode: "9.4.1"
77
steps:
88
- checkout
9+
- run: xcrun simctl list
910
- run:
1011
name: Install build dependencies
1112
command: |

AnalyticsTests/AnalyticsTests.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,18 @@ class AnalyticsTests: QuickSpec {
121121
let integration = analytics.test_integrationsManager()?.test_segmentIntegration()
122122
expect(integration).notTo(beNil())
123123

124-
var sent = 0
125-
126124
analytics.flush()
127-
integration?.test_dispatchBackground {
128-
if let count = integration?.test_queue()?.count {
129-
sent = count
130-
}
131-
else {
132-
sent = -1
125+
waitUntil(timeout: 60) {done in
126+
let queue = DispatchQueue(label: "test")
127+
128+
queue.async {
129+
while(integration?.test_queue()?.count != max) {
130+
sleep(1)
131+
}
132+
133+
done()
133134
}
134135
}
135-
136-
expect(sent).toEventually(equal(max))
137136
}
138137

139138
it("protocol conformance should not interfere with UIApplication interface") {

AnalyticsTests/EndToEndTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class AnalyticsE2ETests: QuickSpec {
6565

6666
analytics.track("E2E Test", properties: ["id": uuid])
6767

68-
self.waitForExpectations(timeout: 20)
68+
self.waitForExpectations(timeout: 3 * 60)
6969

70-
for _ in 1...5 {
70+
for _ in 1...3 * 30 {
7171
sleep(2)
7272
if hasMatchingId(messageId: uuid) {
7373
return

0 commit comments

Comments
 (0)