Skip to content

Commit

Permalink
trying to fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
patduin committed Apr 18, 2024
1 parent 0d9d7fb commit 98744c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@
public class ServerSocketRule extends ExternalResource {
private static final Logger LOG = LoggerFactory.getLogger(ServerSocketRule.class);

private final InetSocketAddress address;
private final ByteArrayOutputStream output = new ByteArrayOutputStream();

private final ServerSocketChannel serverSocketChannel;
private InetSocketAddress address;
private ByteArrayOutputStream output;
private ServerSocketChannel serverSocketChannel;

private int requests = 0;

public ServerSocketRule() {
public ServerSocketRule() {}

@Override
protected void before() throws Throwable {
try {
output = new ByteArrayOutputStream();
serverSocketChannel = (ServerSocketChannel) ServerSocketChannel
.open()
.bind(new InetSocketAddress(0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.net.ConnectException;
import java.net.Socket;

import org.junit.Before;
import org.junit.Test;

public class ServerSocketRuleTest {
Expand All @@ -33,6 +34,11 @@ private void sendData(int port, byte[] bytes) throws Exception {
}
}

@Before
public void setUp() throws Throwable {
rule.before();
}

@Test
public void typical() throws Throwable {
sendData(rule.port(), "my-data".getBytes());
Expand Down

0 comments on commit 98744c3

Please sign in to comment.