From 790f8b44a837510388496d61a575c5fa58041717 Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Tue, 7 Nov 2023 15:50:43 +0800 Subject: [PATCH] testNotifyServerSubscribeAndNotifies 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 b5cff95d2..3f70c0bf9 100644 --- a/Example/IntegrationTests/Push/NotifyTests.swift +++ b/Example/IntegrationTests/Push/NotifyTests.swift @@ -146,12 +146,11 @@ final class NotifyTests: XCTestCase { let expectation = expectation(description: "expects client B to receive subscription after both clients are registered and client A creates one") expectation.assertForOverFulfill = false - var subscription: NotifySubscription! + var subscription: NotifySubscription? let clientB = makeWalletClient(prefix: "👐🏼 Wallet B: ") clientB.subscriptionsPublisher.sink { subscriptions in - guard let newSubscription = subscriptions.first else { return } - subscription = newSubscription + subscription = subscriptions.first expectation.fulfill() }.store(in: &publishers) @@ -161,7 +160,9 @@ final class NotifyTests: XCTestCase { await fulfillment(of: [expectation], timeout: InputConfig.defaultTimeout) - try await clientB.deleteSubscription(topic: subscription.topic) + if let subscription { + try await clientB.deleteSubscription(topic: subscription.topic) + } } func testWalletCreatesAndUpdatesSubscription() async throws { @@ -207,6 +208,7 @@ final class NotifyTests: XCTestCase { let messageExpectation = expectation(description: "receives a notify message") var notifyMessage: NotifyMessage! + var notifyMessageRecord: NotifyMessageRecord? var didNotify = false walletNotifyClientA.subscriptionsPublisher @@ -231,19 +233,20 @@ final class NotifyTests: XCTestCase { }.store(in: &publishers) walletNotifyClientA.notifyMessagePublisher - .sink { [unowned self] notifyMessageRecord in - XCTAssertEqual(notifyMessageRecord.message, notifyMessage) - - Task(priority: .high) { - try await walletNotifyClientA.deleteSubscription(topic: notifyMessageRecord.topic) - messageExpectation.fulfill() - } + .sink { newNotifyMessageRecord in + XCTAssertEqual(newNotifyMessageRecord.message, notifyMessage) + notifyMessageRecord = newNotifyMessageRecord + messageExpectation.fulfill() }.store(in: &publishers) try! await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign) try! await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account) await fulfillment(of: [subscribeExpectation, messageExpectation], timeout: InputConfig.defaultTimeout) + + if let notifyMessageRecord { + try await walletNotifyClientA.deleteSubscription(topic: notifyMessageRecord.topic) + } } }