@@ -134,6 +134,7 @@ - (void)testMultiplexerCanFetchForwardedChannelWithHostPort {
134134}
135135
136136- (void )testCanFetchChannelWithHostPortConcurrently {
137+ dispatch_queue_t testQueue = dispatch_queue_create (" com.google.edo.test" , DISPATCH_QUEUE_SERIAL);
137138 int numOfChannels = 200 ;
138139 EDOChannelMultiplexer *multiplexer = [[EDOChannelMultiplexer alloc ] init ];
139140 [multiplexer start: nil error: nil ];
@@ -158,7 +159,9 @@ - (void)testCanFetchChannelWithHostPortConcurrently {
158159 XCTAssertEqualObjects (port, receivedPort);
159160 [channel sendData: deviceIdentifier withCompletionHandler: nil ];
160161 }];
161- savedChannels[idx] = channel;
162+ dispatch_async (testQueue, ^{
163+ savedChannels[idx] = channel;
164+ });
162165 });
163166 });
164167
@@ -175,6 +178,7 @@ - (void)testCanFetchChannelWithHostPortConcurrently {
175178}
176179
177180- (void )testCanFetchChannelWithBothCorrectAndIncorrectAckConcurrently {
181+ dispatch_queue_t testQueue = dispatch_queue_create (" com.google.edo.test" , DISPATCH_QUEUE_SERIAL);
178182 int numOfChannels = 30 ;
179183 EDOChannelMultiplexer *multiplexer = [[EDOChannelMultiplexer alloc ] init ];
180184 [multiplexer start: nil error: nil ];
@@ -184,6 +188,7 @@ - (void)testCanFetchChannelWithBothCorrectAndIncorrectAckConcurrently {
184188 NSData *deviceInfo = [@" info" dataUsingEncoding: NSUTF8StringEncoding];
185189 NSData *incorrectAck = [@" deadbeef" dataUsingEncoding: NSUTF8StringEncoding];
186190 XCTestExpectation *expectChannelCreated = [self expectationWithDescription: @" Channels created." ];
191+ expectChannelCreated.expectedFulfillmentCount = numOfChannels;
187192
188193 NS_VALID_UNTIL_END_OF_SCOPE NSMutableArray <id > *savedChannels = [[NSMutableArray alloc ] init ];
189194 // Add the placeholders first.
@@ -221,9 +226,11 @@ - (void)testCanFetchChannelWithBothCorrectAndIncorrectAckConcurrently {
221226 [channel sendData: deviceIdentifier withCompletionHandler: nil ];
222227 }];
223228 }
224- savedChannels[idx] = channel;
229+ dispatch_async (testQueue, ^{
230+ savedChannels[idx] = channel;
231+ [expectChannelCreated fulfill ];
232+ });
225233 });
226- [expectChannelCreated fulfill ];
227234 });
228235
229236 int numOfBadChannels = (numOfChannels + 1 ) / 3 ;
0 commit comments