Skip to content

Commit 71ffa30

Browse files
committed
test: close in the description callback only once createOffer has returned
The result of setting the description is dropped only when the connection is freed right after the callback, which waits for methods running on other threads: the createOffer of the test thread had not always returned.
1 parent 2e1205e commit 71ffa30

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎webrtc/src/test/java/dev/onvoid/webrtc/RTCPeerConnectionSignalingTests.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ void closeBeforeDescriptionResultFailsObserver() throws Exception {
209209
connection.createDataChannel("data", new RTCDataChannelInit());
210210

211211
TestSetDescObserver applied = new TestSetDescObserver();
212+
CountDownLatch issued = new CountDownLatch(1);
212213
CountDownLatch closed = new CountDownLatch(1);
213214
AtomicReference<Throwable> failure = new AtomicReference<>();
214215

@@ -219,8 +220,15 @@ public void onSuccess(RTCSessionDescription description) {
219220
// waits for the offer, whose result is posted to that thread.
220221
// Closing from here takes effect once this returns, before the
221222
// result of setting the description is posted in turn, and
222-
// WebRTC drops that result with the connection.
223+
// WebRTC drops that result with the connection. It does so
224+
// only when the connection is freed right away, which waits
225+
// for every method still running on another thread: here the
226+
// createOffer below, which may not have returned yet.
223227
try {
228+
if (!issued.await(5, TimeUnit.SECONDS)) {
229+
throw new IllegalStateException("createOffer did not return");
230+
}
231+
224232
connection.createOffer(new RTCOfferOptions(), new TestCreateDescObserver());
225233
connection.setLocalDescription(applied);
226234
connection.close();
@@ -238,6 +246,8 @@ public void onFailure(String error) {
238246
}
239247
});
240248

249+
issued.countDown();
250+
241251
assertTrue(closed.await(5, TimeUnit.SECONDS), "Offer was not created");
242252
assertNull(failure.get());
243253

0 commit comments

Comments
 (0)