From 5076c9c3db76ee0a924d98aafabf103be5f65c2d Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Tue, 7 Nov 2023 15:47:27 +0800 Subject: [PATCH] testNotifyWatchSubscriptions refactored --- .../IntegrationTests/Push/NotifyTests.swift | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Example/IntegrationTests/Push/NotifyTests.swift b/Example/IntegrationTests/Push/NotifyTests.swift index 65ff1e5e6..b5cff95d2 100644 --- a/Example/IntegrationTests/Push/NotifyTests.swift +++ b/Example/IntegrationTests/Push/NotifyTests.swift @@ -112,7 +112,7 @@ final class NotifyTests: XCTestCase { try await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign) try await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account) - wait(for: [expectation], timeout: InputConfig.defaultTimeout) + await fulfillment(of: [expectation], timeout: InputConfig.defaultTimeout) if let subscription { try await walletNotifyClientA.deleteSubscription(topic: subscription.topic) @@ -123,20 +123,23 @@ final class NotifyTests: XCTestCase { let expectation = expectation(description: "expects client B to receive subscription created by client A") expectation.assertForOverFulfill = false + var subscription: NotifySubscription? + let clientB = makeWalletClient(prefix: "👐🏼 Wallet B: ") clientB.subscriptionsPublisher.sink { subscriptions in - guard let subscription = subscriptions.first else { return } - Task(priority: .high) { - try await clientB.deleteSubscription(topic: subscription.topic) - expectation.fulfill() - } + subscription = subscriptions.first + expectation.fulfill() }.store(in: &publishers) try! await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign) try! await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account) try! await clientB.register(account: account, domain: gmDappDomain, onSign: sign) - wait(for: [expectation], timeout: InputConfig.defaultTimeout) + await fulfillment(of: [expectation], timeout: InputConfig.defaultTimeout) + + if let subscription { + try await clientB.deleteSubscription(topic: subscription.topic) + } } func testNotifySubscriptionChanged() async throws { @@ -156,7 +159,7 @@ final class NotifyTests: XCTestCase { try! await clientB.register(account: account, domain: gmDappDomain, onSign: sign) try! await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account) - wait(for: [expectation], timeout: InputConfig.defaultTimeout) + await fulfillment(of: [expectation], timeout: InputConfig.defaultTimeout) try await clientB.deleteSubscription(topic: subscription.topic) } @@ -186,12 +189,12 @@ final class NotifyTests: XCTestCase { try await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign) try await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account) - wait(for: [created], timeout: InputConfig.defaultTimeout) + await fulfillment(of: [created], timeout: InputConfig.defaultTimeout) let updateScope = Set([subscription.scope.keys.first!]) try await walletNotifyClientA.update(topic: subscription.topic, scope: updateScope) - wait(for: [updated], timeout: InputConfig.defaultTimeout) + await fulfillment(of: [updated], timeout: InputConfig.defaultTimeout) let updatedScope = Set(subscription.scope.filter { $0.value.enabled == true }.keys) XCTAssertEqual(updatedScope, updateScope) @@ -240,7 +243,7 @@ final class NotifyTests: XCTestCase { try! await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign) try! await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account) - wait(for: [subscribeExpectation, messageExpectation], timeout: InputConfig.defaultTimeout) + await fulfillment(of: [subscribeExpectation, messageExpectation], timeout: InputConfig.defaultTimeout) } }