sdedic commented on a change in pull request #3441:
URL: https://github.com/apache/netbeans/pull/3441#discussion_r782757815



##########
File path: 
java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java
##########
@@ -4846,8 +4849,85 @@ public void saveProject(Project project) throws 
IOException, ClassCastException
         }
     }
     
-    public void testCancelProgressHandle() throws Exception {
+    private static volatile ProgressCommand progressCommandInstance;
+    
+    @ServiceProvider(service = CodeActionsProvider.class)
+    public static class ProgressCommand extends CodeActionsProvider {
+        
+        // command will block before checking for cancel (before return/ 
terminate)
+        CountDownLatch beforeCancel = new CountDownLatch(1);
+        
+        CountDownLatch progressReported = new CountDownLatch(1);
+        
+        /**
+         * True, if the command has received a cancel
+         */
+        AtomicBoolean cancel = new AtomicBoolean(false);
+        
+        /**
+         * True, if the command has finished (normally or abruptly)
+         */
+        AtomicBoolean finished = new AtomicBoolean(false);
+        
+        
+        volatile Throwable exception;
+        
+        public ProgressCommand() {
+            progressCommandInstance = this;
+        }
+        
+        @Override
+        public List<CodeAction> getCodeActions(ResultIterator resultIterator, 
CodeActionParams params) throws Exception {
+            return Collections.emptyList();
+        }
+        
+        boolean cancel() {
+            return !this.cancel.getAndSet(true);
+        }
         
+        @Override
+        public CompletableFuture<Object> processCommand(NbCodeLanguageClient 
client, String command, List<Object> arguments) {
+            if (!command.equals("_progressCommand")) {
+                return null;
+            }
+
+            return CompletableFuture.<Object>supplyAsync(() -> {
+                ProgressHandle h = ProgressHandle.createHandle("Test Command", 
this::cancel);
+                try {
+                    h.start(100, 100);
+                    h.progress(20);
+                    // The Progress infra sometimes coalesces events, so 
definitely deliver begin + progress before
+                    // waking up the client controller that will issue cancel. 
Otherwise begin / cancel could be merged into
+                    // a no-op.
+                    Thread.sleep(1000);

Review comment:
       No :( or not in a way I am aware of: events may be coalesced right in 
the loop, the even queue is private, its RequestProcessor as well. And there's 
also transport from the server > client which is done over sockets = at least 
one another thread hand-off, so even I could eventually patch the `Controller` 
in Progress module and watch when the event queue empties, the event could be 
still partially somewhere between LSP Server and Client I guess.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to