Skip to content

Commit 2e973aa

Browse files
committed
set send timeout to 100ms, fix resist_dsd_timeout test
1 parent d6b8285 commit 2e973aa

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.concurrent.TimeUnit;
2323
import jnr.unixsocket.UnixSocketAddress;
2424
import jnr.unixsocket.UnixDatagramChannel;
25+
import jnr.unixsocket.UnixSocketOptions;
2526

2627

2728
/**
@@ -318,6 +319,7 @@ public NonBlockingStatsDClient(final String prefix, final int queueSize, String
318319
final SocketAddress address = addressLookup.call();
319320
if (address instanceof UnixSocketAddress) {
320321
clientChannel = UnixDatagramChannel.open();
322+
clientChannel.setOption(UnixSocketOptions.SO_SNDTIMEO, Integer.valueOf(100));
321323
} else{
322324
clientChannel = DatagramChannel.open();
323325
}

src/test/java/com/timgroup/statsd/UnixSocketTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void start() throws IOException {
3232
socketFile.deleteOnExit();
3333

3434
server = new DummyStatsDServer(socketFile.toString());
35-
client = new NonBlockingStatsDClient("my.prefix", socketFile.toString(), 0, null, this);
35+
client = new NonBlockingStatsDClient("my.prefix", socketFile.toString(), 0, 1, null, this);
3636
}
3737

3838
@After
@@ -103,9 +103,9 @@ public void resist_dsd_timeout() throws Exception {
103103
server.freeze();
104104
while(lastException.getMessage() == null) {
105105
client.gauge("mycount", 20);
106-
Thread.sleep(1); // We need to fill the buffer, setting a shorter sleep
106+
Thread.sleep(10); // We need to fill the buffer, setting a shorter sleep
107107
}
108-
assertThat(lastException.getMessage(), containsString("No buffer space available"));
108+
assertThat(lastException.getMessage(), containsString("Resource temporarily unavailable"));
109109

110110
// Make sure we recover after we resume listening
111111
server.clear();

0 commit comments

Comments
 (0)