Skip to content

Commit

Permalink
Add a timeout on simulator devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Aug 21, 2024
1 parent ae772fd commit f748e92
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ public struct RegisterRemoteNotificationsAction: Sendable {

try await registration.access.waitCheckingCancellation()

#if targetEnvironment(simulator)
async let _ = withTimeout(of: .seconds(10)) { @MainActor in
spezi.storage[RemoteNotificationContinuation.self]?.resume(with: .failure(TimeoutError()))
}
#endif

return try await withCheckedThrowingContinuation { continuation in
assert(registration.continuation == nil, "continuation wasn't nil")
registration.continuation = continuation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ struct RemoteNotificationsTestView: View {
if let token {
Text(token.description)
.foregroundStyle(.green)
} else if let error = error as? LocalizedError,
let description = error.errorDescription ?? error.failureReason {
Text(verbatim: description)
.foregroundStyle(.red)
} else if error != nil {
Text(verbatim: "failed")
.foregroundStyle(.red)
Expand Down
11 changes: 10 additions & 1 deletion Tests/UITests/TestAppUITests/RemoteNotificationsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import XCTest


final class RemoteNotificationsTests: XCTestCase {
@MainActor
override func setUp() async throws {
continueAfterFailure = false
}

@MainActor
func testRegistrationOnSimulator() throws {
let app = XCUIApplication()
Expand All @@ -26,7 +31,11 @@ final class RemoteNotificationsTests: XCTestCase {
XCTAssertTrue(app.buttons["Unregister"].exists)

app.buttons["Register"].tap()
XCTAssertTrue(app.staticTexts["Token, 80 bytes"].waitForExistence(timeout: 1.0))

if !app.staticTexts["Token, 80 bytes"].waitForExistence(timeout: 1.0) {
XCTAssertFalse(app.staticTexts["Token, failed"].exists)
XCTAssertTrue(app.staticTexts["Token, Timeout"].waitForExistence(timeout: 15))
}

app.buttons["Unregister"].tap()
XCTAssertTrue(app.staticTexts["Token, none"].waitForExistence(timeout: 1.0))
Expand Down

0 comments on commit f748e92

Please sign in to comment.