Skip to content

Commit 1a10bf7

Browse files
authored
Merge pull request #2 from eed3si9n/wip/test
Test cleans after itself
2 parents d87565c + 8c71879 commit 1a10bf7

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/test/java/org/scalasbt/ipcsocket/UnixDomainSocketTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
import java.net.ServerSocket;
1414
import java.net.Socket;
1515
import java.util.concurrent.CompletableFuture;
16+
import java.util.Random;
1617

1718
public class UnixDomainSocketTest {
1819
@Test
1920
public void testAssertEquals() throws IOException, InterruptedException {
21+
Random rand = new Random();
2022
Path tempDir = Files.createTempDirectory("ipcsocket");
21-
Path sock = tempDir.resolve("foo.sock");
23+
Path sock = tempDir.resolve("foo" + rand.nextInt() + ".sock");
24+
ServerSocket serverSocket = new UnixDomainServerSocket(sock.toString());
2225

2326
CompletableFuture<Boolean> server = CompletableFuture.supplyAsync(() -> {
2427
try {
25-
ServerSocket serverSocket = new UnixDomainServerSocket(sock.toString());
2628
EchoServer echo = new EchoServer(serverSocket);
2729
echo.run();
2830
} catch (IOException e) { }
@@ -39,6 +41,7 @@ public void testAssertEquals() throws IOException, InterruptedException {
3941
String line = in.readLine();
4042
client.close();
4143
server.cancel(true);
44+
serverSocket.close();
4245
assertEquals("echo did not return the content", line, "hello");
4346
}
4447
}

src/test/java/org/scalasbt/ipcsocket/Win32NamedPipeSocketTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
import java.net.ServerSocket;
1414
import java.net.Socket;
1515
import java.util.concurrent.CompletableFuture;
16+
import java.util.Random;
1617

1718
public class Win32NamedPipeSocketTest {
1819
@Test
1920
public void testAssertEquals() throws IOException, InterruptedException {
20-
String pipeName = "\\\\.\\pipe\\ipcsockettest";
21+
Random rand = new Random();
22+
String pipeName = "\\\\.\\pipe\\ipcsockettest" + rand.nextInt();
23+
ServerSocket serverSocket = new Win32NamedPipeServerSocket(pipeName);
2124
CompletableFuture<Boolean> server = CompletableFuture.supplyAsync(() -> {
2225
try {
23-
ServerSocket serverSocket = new Win32NamedPipeServerSocket(pipeName);
2426
EchoServer echo = new EchoServer(serverSocket);
2527
echo.run();
2628
} catch (IOException e) { }
@@ -38,6 +40,7 @@ public void testAssertEquals() throws IOException, InterruptedException {
3840
System.out.println("windows client: " + line);
3941
client.close();
4042
server.cancel(true);
43+
serverSocket.close();
4144
assertEquals("echo did not return the content", line, "hello");
4245
}
4346
}

0 commit comments

Comments
 (0)