Skip to content

Commit 4db9bee

Browse files
committed
fix concurrency issue
1 parent 5dbde94 commit 4db9bee

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/test/java/com/github/dockerjava/netty/exec/AttachContainerCmdExecTest.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dockerjava.netty.exec;
22

3+
import static java.util.concurrent.TimeUnit.SECONDS;
34
import static org.hamcrest.MatcherAssert.assertThat;
45
import static org.hamcrest.Matchers.containsString;
56
import static org.hamcrest.Matchers.isEmptyString;
@@ -70,7 +71,7 @@ public void onNext(Frame frame) {
7071
};
7172

7273
dockerClient.attachContainerCmd(container.getId()).withStdErr(true).withStdOut(true).withFollowStream(true)
73-
.withLogs(true).exec(callback).awaitCompletion(10, TimeUnit.SECONDS);
74+
.withLogs(true).exec(callback).awaitCompletion(10, SECONDS);
7475
callback.close();
7576

7677
assertThat(callback.toString(), containsString(snippet));
@@ -81,33 +82,40 @@ public void attachContainerWithStdin() throws Exception {
8182

8283
String snippet = "hello world";
8384

84-
CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("/bin/sh", "-c", "read line && echo $line")
85-
.withTty(false).withStdinOpen(true).exec();
85+
CreateContainerResponse container = dockerClient.createContainerCmd("busybox")
86+
.withCmd("/bin/sh", "-c", "sleep 1 && read line && echo $line")
87+
.withTty(false)
88+
.withStdinOpen(true)
89+
.exec();
8690

8791
LOG.info("Created container: {}", container.toString());
8892
assertThat(container.getId(), not(isEmptyString()));
8993

9094
dockerClient.startContainerCmd(container.getId()).exec();
9195

96+
Thread.sleep(SECONDS.toMillis(3)); //wait bash initialisation
97+
9298
InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
9399

94100
assertTrue(inspectContainerResponse.getState().getRunning());
95101

96102
AttachContainerTestCallback callback = new AttachContainerTestCallback() {
97-
98103
@Override
99104
public void onNext(Frame frame) {
100105
assertEquals(frame.getStreamType(), StreamType.STDOUT);
101106
super.onNext(frame);
102-
};
107+
}
103108
};
104109

105110
InputStream stdin = new ByteArrayInputStream((snippet + "\n").getBytes());
106111

107-
dockerClient.attachContainerCmd(container.getId()).withStdErr(true).withStdOut(true).withFollowStream(true)
112+
dockerClient.attachContainerCmd(container.getId())
113+
.withStdErr(true)
114+
.withStdOut(true)
115+
.withFollowStream(true)
108116
.withStdIn(stdin)
109117
.exec(callback)
110-
.awaitCompletion(5, TimeUnit.SECONDS);
118+
.awaitCompletion(15, SECONDS);
111119
callback.close();
112120

113121
assertThat(callback.toString(), containsString(snippet));
@@ -141,7 +149,7 @@ public void onNext(Frame frame) {
141149
.withStdOut(true)
142150
.withFollowStream(true)
143151
.exec(callback)
144-
.awaitCompletion(10, TimeUnit.SECONDS);
152+
.awaitCompletion(10, SECONDS);
145153
callback.close();
146154

147155
// HexDump.dump(collectFramesCallback.toString().getBytes(), 0, System.out, 0);

0 commit comments

Comments
 (0)