Skip to content

Commit

Permalink
WebSockets Next: attempt to diagnose flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Mar 7, 2024
1 parent b1a3686 commit 2aed4c8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void assertBroadcast(URI testUri) throws Exception {
assertTrue(connectedLatch.await(5, TimeUnit.SECONDS));
ws1.get().writeTextMessage("hello");
assertTrue(onMessageLatch.await(5, TimeUnit.SECONDS));
assertEquals(2, messages.size());
assertEquals(2, messages.size(), "Messages: " + messages);
// Both messages come from the first client
assertEquals("1:HELLO", messages.get(0));
assertEquals("1:HELLO", messages.get(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void assertBroadcast(URI testUri) throws Exception {
}
});
assertTrue(c2ConnectedLatch.await(5, TimeUnit.SECONDS));
assertTrue(c2MessageLatch.await(10, TimeUnit.SECONDS));
assertTrue(c2MessageLatch.await(5, TimeUnit.SECONDS), "Messages: " + messages);
// onOpen should be broadcasted to both clients
assertEquals(2, messages.size());
assertEquals("c2", messages.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,18 @@ protected Uni<Void> sendText(String message, boolean broadcast) {
}

protected Uni<Void> multiText(Multi<Object> multi, boolean broadcast, Function<Object, Uni<Void>> itemFun) {
multi.onFailure().call(connection::close).subscribe().with(
m -> {
itemFun.apply(m).subscribe().with(v -> LOG.debugf("Multi >> text message: %s", connection),
t -> LOG.errorf(t, "Unable to send text message from Multi: %s", connection));
});
multi.onFailure()
.call(connection::close)
.subscribe().with(
m -> {
itemFun.apply(m)
.subscribe()
.with(v -> LOG.debugf("Multi >> text message: %s", connection),
t -> LOG.errorf(t, "Unable to send text message from Multi: %s", connection));
},
t -> {
LOG.errorf(t, "Unable to send text message from Multi - connection was closed: %s ", connection);
});
return Uni.createFrom().voidItem();
}

Expand All @@ -221,11 +228,18 @@ protected Uni<Void> sendBinary(Buffer message, boolean broadcast) {
}

protected Uni<Void> multiBinary(Multi<Object> multi, boolean broadcast, Function<Object, Uni<Void>> itemFun) {
multi.onFailure().call(connection::close).subscribe().with(
m -> {
itemFun.apply(m).subscribe().with(v -> LOG.debugf("Multi >> binary message: %s", connection),
t -> LOG.errorf(t, "Unable to send binary message from Multi: %s", connection));
});
multi.onFailure()
.call(connection::close)
.subscribe().with(
m -> {
itemFun.apply(m)
.subscribe()
.with(v -> LOG.debugf("Multi >> binary message: %s", connection),
t -> LOG.errorf(t, "Unable to send binary message from Multi: %s", connection));
},
t -> {
LOG.errorf(t, "Unable to send text message from Multi - connection was closed: %s ", connection);
});
return Uni.createFrom().voidItem();
}
}

0 comments on commit 2aed4c8

Please sign in to comment.