Skip to content

Commit 82727b3

Browse files
committed
Re-order testAsyncSequencePublishListener
1 parent 34bbe42 commit 82727b3

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Tests/MQTTNIOTests/MQTTNIOTests+async.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ final class AsyncMQTTNIOTests: XCTestCase {
108108

109109
func testAsyncSequencePublishListener() {
110110
let expectation = XCTestExpectation(description: "testAsyncSequencePublishListener")
111-
expectation.expectedFulfillmentCount = 3
111+
expectation.expectedFulfillmentCount = 2
112+
let finishExpectation = XCTestExpectation(description: "testAsyncSequencePublishListener.finish")
113+
finishExpectation.expectedFulfillmentCount = 1
112114

113115
let client = self.createClient(identifier: "testAsyncSequencePublishListener+async", version: .v5_0)
114116
let client2 = self.createClient(identifier: "testAsyncSequencePublishListener+async2", version: .v5_0)
@@ -131,31 +133,33 @@ final class AsyncMQTTNIOTests: XCTestCase {
131133
XCTFail("\(error)")
132134
}
133135
}
134-
expectation.fulfill()
136+
finishExpectation.fulfill()
135137
}
136138
try await client.publish(to: "TestSubject", payload: ByteBufferAllocator().buffer(string: payloadString), qos: .atLeastOnce)
137139
try await client.publish(to: "TestSubject", payload: ByteBufferAllocator().buffer(string: payloadString), qos: .atLeastOnce)
138140
try await client.disconnect()
139-
Thread.sleep(forTimeInterval: 0.5)
141+
142+
self.wait(for: [expectation], timeout: 5.0)
143+
140144
try await client2.disconnect()
141-
Thread.sleep(forTimeInterval: 0.5)
142145
try await client.shutdown()
143146
try await client2.shutdown()
144147

148+
self.wait(for: [finishExpectation], timeout: 5.0)
149+
145150
_ = await task.result
146151
}
147-
wait(for: [expectation], timeout: 5.0)
148152
}
149153

150154
func testAsyncSequencePublishSubscriptionIdListener() {
151-
let client = self.createClient(identifier: "testAsyncSequencePublishSubscriptionIdListener+async", version: .v5_0)
152-
let client2 = self.createClient(identifier: "testAsyncSequencePublishSubscriptionIdListener+async2", version: .v5_0)
153-
let payloadString = "Hello"
154155
let expectation = XCTestExpectation(description: "publish listener")
155156
let expectation2 = XCTestExpectation(description: "publish listener2")
156157
expectation.expectedFulfillmentCount = 3
157158
expectation2.expectedFulfillmentCount = 2
158159

160+
let client = self.createClient(identifier: "testAsyncSequencePublishSubscriptionIdListener+async", version: .v5_0)
161+
let client2 = self.createClient(identifier: "testAsyncSequencePublishSubscriptionIdListener+async2", version: .v5_0)
162+
let payloadString = "Hello"
159163
self.XCTRunAsyncAndBlock {
160164
try await client.connect()
161165
try await client2.connect()

0 commit comments

Comments
 (0)