@@ -17,8 +17,8 @@ public class UnixSocketTest implements StatsDClientErrorHandler {
1717 private static File tmpFolder ;
1818 private static NonBlockingStatsDClient client ;
1919 private static DummyStatsDServer server ;
20- private Exception lastException = new Exception ();
2120 private static File socketFile ;
21+ private volatile Exception lastException = new Exception ();
2222
2323 public void handle (Exception exception ) {
2424 lastException = exception ;
@@ -63,19 +63,17 @@ public void resist_dsd_restart() throws Exception {
6363
6464 // Close the server, client should throw an IOException
6565 server .close ();
66- client .gauge ("mycount" , 20 );
6766 while (lastException .getMessage () == null ) {
68- // Wait until we flush and get the exception
67+ client . gauge ( "mycount" , 20 );
6968 Thread .sleep (10 );
7069 }
7170 assertThat (lastException .getMessage (), containsString ("Connection refused" ));
7271
7372 // Delete the socket file, client should throw an IOException
7473 lastException = new Exception ();
7574 socketFile .delete ();
76- client .gauge ("mycount" , 20 );
7775 while (lastException .getMessage () == null ) {
78- // Wait until we flush and get the exception
76+ client . gauge ( "mycount" , 20 );
7977 Thread .sleep (10 );
8078 }
8179 assertThat (lastException .getMessage (), containsString ("No such file or directory" ));
@@ -105,11 +103,12 @@ public void resist_dsd_timeout() throws Exception {
105103 server .freeze ();
106104 while (lastException .getMessage () == null ) {
107105 client .gauge ("mycount" , 20 );
108- Thread .sleep (50 );
106+ Thread .sleep (1 ); // We need to fill the buffer, setting a shorter sleep
109107 }
110108 assertThat (lastException .getMessage (), containsString ("No buffer space available" ));
111109
112110 // Make sure we recover after we resume listening
111+ server .clear ();
113112 server .unfreeze ();
114113 while (!server .messagesReceived ().contains ("my.prefix.mycount:30|g" )) {
115114 server .clear ();
0 commit comments