Skip to content

Commit 9bd814b

Browse files
authored
Merge pull request #129 from jonahkichwacoders/bug128
Bug #128: Ensure that client is computing before issuing cancel
2 parents a9bbfbd + 498b643 commit 9bd814b

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)