Skip to content

Commit 498b643

Browse files
committed
Bug #128: Ensure that client is computing before issuing cancel
This test is trying to verify that the cancel token was working as expected. However there was a race condition in the test that meant if the cancel was acted on before the computeAsync was run the computeAsync would not be run. This caused an intermittent test failure because cancellationHappened[0] would never be set to true, even though the client would act on the cancellation. Signed-off-by: Jonah Graham <[email protected]>
1 parent a9bbfbd commit 498b643

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/IntegrationTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public void testCancellation() throws Exception {
101101

102102
in.connect(out2);
103103
out.connect(in2);
104-
104+
105+
boolean[] inComputeAsync = new boolean[1];
105106
boolean[] cancellationHappened = new boolean[1];
106107

107108
MyClient client = new MyClient() {
@@ -110,6 +111,7 @@ public CompletableFuture<MyParam> askClient(MyParam param) {
110111
return CompletableFutures.computeAsync(cancelToken -> {
111112
try {
112113
long startTime = System.currentTimeMillis();
114+
inComputeAsync[0] = true;
113115
do {
114116
cancelToken.checkCanceled();
115117
Thread.sleep(50);
@@ -138,8 +140,16 @@ public CompletableFuture<MyParam> askServer(MyParam param) {
138140
serverSideLauncher.startListening();
139141

140142
CompletableFuture<MyParam> future = serverSideLauncher.getRemoteProxy().askClient(new MyParam("FOO"));
141-
future.cancel(true);
143+
142144
long startTime = System.currentTimeMillis();
145+
while (!inComputeAsync[0]) {
146+
Thread.sleep(50);
147+
if (System.currentTimeMillis() - startTime > TIMEOUT)
148+
Assert.fail("Timeout waiting for client to start computing.");
149+
}
150+
future.cancel(true);
151+
152+
startTime = System.currentTimeMillis();
143153
while (!cancellationHappened[0]) {
144154
Thread.sleep(50);
145155
if (System.currentTimeMillis() - startTime > TIMEOUT)

0 commit comments

Comments
 (0)