JaroslavTulach commented on a change in pull request #3441:
URL: https://github.com/apache/netbeans/pull/3441#discussion_r782713255
##########
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:
`Thread.sleep` is just a request for random failures (under load, for
example). Can't the test verify an event has been delivered via the
`ProgressHandle` infrastructure somehow?
--
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