Skip to content

Commit 0df4994

Browse files
committed
testWhenBatchFails_thenIntervalIncreases fails when expectation.fulfill called multiple times
1 parent fe831f0 commit 0df4994

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Tests/ExportersTests/PersistenceExporter/Export/DataExportWorkerTests.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class DataExportWorkerTests: XCTestCase {
138138

139139
func testWhenBatchFails_thenIntervalIncreases() {
140140
let delayChangeExpectation = expectation(description: "Export delay is increased")
141+
141142
let mockDelay = MockDelay { command in
142143
if case .increase = command {
143144
delayChangeExpectation.fulfill()
@@ -146,11 +147,20 @@ class DataExportWorkerTests: XCTestCase {
146147
}
147148
}
148149

149-
let exportExpectation = self.expectation(description: "value exported")
150-
150+
let exportExpectation = expectation(description: "value exported")
151+
152+
// The onExport closure is called more than once as part of test execution
153+
// It does not seem to be called the same number of times on each test run.
154+
// Setting `assertForOverFulfill` to `false` works around the XCTestExpectation
155+
// error that fails the test.
156+
// "API violation - multiple calls made to -[XCTestExpectation fulfill] for value exported."
157+
exportExpectation.assertForOverFulfill = false
158+
151159
var mockDataExporter = DataExporterMock(exportStatus: .mockWith(needsRetry: true))
152-
153-
mockDataExporter.onExport = { data in exportExpectation.fulfill() }
160+
161+
mockDataExporter.onExport = { data in
162+
exportExpectation.fulfill()
163+
}
154164

155165
// When
156166
let fileReader = FileReaderMock()

0 commit comments

Comments
 (0)