Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Sep 19, 2024
1 parent 9a6ab46 commit 1558d22
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions Tests/RelayerTests/AutomaticSocketConnectionHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ final class AutomaticSocketConnectionHandlerTests: XCTestCase {
appStateObserver.currentState = .foreground // Ensure app is in the foreground

// Ensure socket is disconnected initially
webSocketSession.disconnect()
XCTAssertFalse(webSocketSession.isConnected)
webSocketSession.isConnected = false

let expectation = XCTestExpectation(description: "WebSocket should connect when reconnectIfNeeded is called")

Expand All @@ -173,7 +172,6 @@ final class AutomaticSocketConnectionHandlerTests: XCTestCase {
sut.reconnectIfNeeded()

wait(for: [expectation], timeout: 5.0) // Increased timeout

Check failure on line 174 in Tests/RelayerTests/AutomaticSocketConnectionHandlerTests.swift

View workflow job for this annotation

GitHub Actions / test (unit-tests)

testReconnectIfNeededWhenSubscribed, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "WebSocket should connect when reconnectIfNeeded is called".
XCTAssertTrue(webSocketSession.isConnected)
}

func testReconnectIfNeededWhenNotSubscribed() {
Expand Down Expand Up @@ -218,9 +216,10 @@ final class AutomaticSocketConnectionHandlerTests: XCTestCase {

// Simulate immediate reconnection attempts
for _ in 0..<sut.maxImmediateAttempts {
print("Simulating disconnection")
socketStatusProviderMock.simulateConnectionStatus(.disconnected)
// Wait to allow the handler to process each disconnection
try? await Task.sleep(nanoseconds: 200_000_000) // 200ms
try? await Task.sleep(nanoseconds: 500_000_000) // 200ms
}

// Simulate one more disconnection to trigger switching to periodic reconnection
Expand All @@ -243,9 +242,9 @@ final class AutomaticSocketConnectionHandlerTests: XCTestCase {
// Simulate immediate reconnection attempts
for _ in 0...sut.maxImmediateAttempts {
socketStatusProviderMock.simulateConnectionStatus(.disconnected)
try? await Task.sleep(nanoseconds: 100_000_000) // 100ms
try? await Task.sleep(nanoseconds: 300_000_000) // 100ms
}
try? await Task.sleep(nanoseconds: 100_000_000) // 100ms
try? await Task.sleep(nanoseconds: 300_000_000) // 100ms

// Now simulate the connection being successful
socketStatusProviderMock.simulateConnectionStatus(.connected)
Expand Down Expand Up @@ -281,7 +280,7 @@ final class AutomaticSocketConnectionHandlerTests: XCTestCase {
// Simulate three disconnections
for _ in 0..<sut.maxImmediateAttempts {
socketStatusProviderMock.simulateConnectionStatus(.disconnected)
try await Task.sleep(nanoseconds: 100_000_000) // Wait 0.001 seconds
try await Task.sleep(nanoseconds: 300_000_000) // Wait 0.001 seconds

}

Expand All @@ -305,7 +304,7 @@ final class AutomaticSocketConnectionHandlerTests: XCTestCase {
}

// Allow handleInternalConnect() to start observing
try await Task.sleep(nanoseconds: 100_000_000) // Wait 0.1 seconds
try await Task.sleep(nanoseconds: 300_000_000) // Wait 0.1 seconds

// Simulate a successful connection
socketStatusProviderMock.simulateConnectionStatus(.connected)
Expand Down Expand Up @@ -341,12 +340,12 @@ final class AutomaticSocketConnectionHandlerTests: XCTestCase {
}

// Allow handleInternalConnect() to start observing
try await Task.sleep(nanoseconds: 100_000_000) // Wait 0.001 seconds
try await Task.sleep(nanoseconds: 300_000_000) // Wait 0.001 seconds

// Simulate two disconnections
for _ in 0..<2 {
socketStatusProviderMock.simulateConnectionStatus(.disconnected)
try await Task.sleep(nanoseconds: 100_000_000) // Wait 0.001 seconds
try await Task.sleep(nanoseconds: 300_000_000) // Wait 0.001 seconds
}

// Simulate a successful connection
Expand Down

0 comments on commit 1558d22

Please sign in to comment.