@@ -108,7 +108,9 @@ final class AsyncMQTTNIOTests: XCTestCase {
108
108
109
109
func testAsyncSequencePublishListener( ) {
110
110
let expectation = XCTestExpectation ( description: " testAsyncSequencePublishListener " )
111
- expectation. expectedFulfillmentCount = 3
111
+ expectation. expectedFulfillmentCount = 2
112
+ let finishExpectation = XCTestExpectation ( description: " testAsyncSequencePublishListener.finish " )
113
+ finishExpectation. expectedFulfillmentCount = 1
112
114
113
115
let client = self . createClient ( identifier: " testAsyncSequencePublishListener+async " , version: . v5_0)
114
116
let client2 = self . createClient ( identifier: " testAsyncSequencePublishListener+async2 " , version: . v5_0)
@@ -131,31 +133,33 @@ final class AsyncMQTTNIOTests: XCTestCase {
131
133
XCTFail ( " \( error) " )
132
134
}
133
135
}
134
- expectation . fulfill ( )
136
+ finishExpectation . fulfill ( )
135
137
}
136
138
try await client. publish ( to: " TestSubject " , payload: ByteBufferAllocator ( ) . buffer ( string: payloadString) , qos: . atLeastOnce)
137
139
try await client. publish ( to: " TestSubject " , payload: ByteBufferAllocator ( ) . buffer ( string: payloadString) , qos: . atLeastOnce)
138
140
try await client. disconnect ( )
139
- Thread . sleep ( forTimeInterval: 0.5 )
141
+
142
+ self . wait ( for: [ expectation] , timeout: 5.0 )
143
+
140
144
try await client2. disconnect ( )
141
- Thread . sleep ( forTimeInterval: 0.5 )
142
145
try await client. shutdown ( )
143
146
try await client2. shutdown ( )
144
147
148
+ self . wait ( for: [ finishExpectation] , timeout: 5.0 )
149
+
145
150
_ = await task. result
146
151
}
147
- wait ( for: [ expectation] , timeout: 5.0 )
148
152
}
149
153
150
154
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 "
154
155
let expectation = XCTestExpectation ( description: " publish listener " )
155
156
let expectation2 = XCTestExpectation ( description: " publish listener2 " )
156
157
expectation. expectedFulfillmentCount = 3
157
158
expectation2. expectedFulfillmentCount = 2
158
159
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 "
159
163
self . XCTRunAsyncAndBlock {
160
164
try await client. connect ( )
161
165
try await client2. connect ( )
0 commit comments