Skip to content

Commit 156e3a4

Browse files
committed
[flaky tests] Testing batched operations need to wait
* Currently the Operation Repo is a singleton and shared between tests, so a pending flush could be on the DispatchQueue from a previous test and it will flush unexpectedly. * This test tests combining operations and intentionally increases the `pollIntervalMilliseconds` to `300`, but a previous flush could interrupt this.
1 parent 1a947c1 commit 156e3a4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

iOS_SDK/OneSignalSDK/OneSignalUserTests/OneSignalUserTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ final class OneSignalUserTests: XCTestCase {
312312
// Increase flush interval to allow all the updates to batch
313313
OSOperationRepo.sharedInstance.pollIntervalMilliseconds = 300
314314

315+
// Wait to let any pending flushes in the Operation Repo to run
316+
OneSignalCoreMocks.waitForBackgroundThreads(seconds: 0.1)
317+
315318
/* When */
316319

317320
OneSignalUserManagerImpl.sharedInstance.sendSessionTime(100)
@@ -349,7 +352,7 @@ final class OneSignalUserTests: XCTestCase {
349352

350353
/* Then */
351354

352-
OneSignalCoreMocks.waitForBackgroundThreads(seconds: 0.5)
355+
OneSignalCoreMocks.waitForBackgroundThreads(seconds: 1)
353356

354357
let expectedPayload: [String: Any] = [
355358
"deltas": [

iOS_SDK/OneSignalSDK/OneSignalUserTests/SwitchUserIntegrationTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import XCTest
22
import OneSignalCore
33
import OneSignalCoreMocks
44
import OneSignalUserMocks
5+
@testable import OneSignalOSCore
56
@testable import OneSignalUser
67

78
final class SwitchUserIntegrationTests: XCTestCase {
@@ -189,6 +190,7 @@ final class SwitchUserIntegrationTests: XCTestCase {
189190
*/
190191
func testAnonUser_thenIdentifyUserWithConflict_thenLogout_sendsCorrectUpdatesWithNoFetch() throws {
191192
/* Setup */
193+
OneSignalCoreMocks.waitForBackgroundThreads(seconds: 0.5)
192194

193195
let client = MockOneSignalClient()
194196
OneSignalCoreImpl.setSharedClient(client)
@@ -316,6 +318,11 @@ final class SwitchUserIntegrationTests: XCTestCase {
316318
let client = MockOneSignalClient()
317319
OneSignalCoreImpl.setSharedClient(client)
318320

321+
// Increase flush interval to allow all the updates to batch
322+
OSOperationRepo.sharedInstance.pollIntervalMilliseconds = 300
323+
// Wait to let any pending flushes in the Operation Repo to run
324+
OneSignalCoreMocks.waitForBackgroundThreads(seconds: 0.1)
325+
319326
// 1. Set up mock responses for the first anonymous user
320327
let tagsUserAnon = ["tag_anon": "value_anon"]
321328
MockUserRequests.setDefaultCreateAnonUserResponses(with: client)

0 commit comments

Comments
 (0)