Skip to content

Commit

Permalink
Fix UnixSocketTest#resist_dsd_restart
Browse files Browse the repository at this point in the history
Avoid sending too many metrics to a closed socket, to avoid a race
condition with the lastException reset.

Occasionally, two metrics will be sent to the client after the server
socket was removed. First one triggers an exception and causes the
send loop to break. Test case then resets the lastException variable,
while the client is still running and has another message buffered. If
that is delivered before the server is started, it triggers another
exception and causes nullValue() check to fail and the end of the test
case.
  • Loading branch information
vickenty committed Sep 2, 2022
1 parent e4fc80f commit 5cdf70a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/test/java/com/timgroup/statsd/UnixSocketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ public void resist_dsd_restart() throws Exception {
// Delete the socket file, client should throw an IOException
lastException = new Exception();
socketFile.delete();

client.gauge("mycount", 21);
while(lastException.getMessage() == null) {
client.gauge("mycount", 20);
Thread.sleep(10);
}
assertThat(lastException.getMessage(), containsString("No such file or directory"));
Expand Down

0 comments on commit 5cdf70a

Please sign in to comment.