You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jt...@apache.org on 2020/12/26 14:40:09 UTC

[netbeans-html4j] 14/25: Try harder to executeNow in asynchronous processors

This is an automated email from the ASF dual-hosted git repository.

jtulach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans-html4j.git

commit a3567854ae6b24a9ab1509c99b71f799f5ceaa3d
Author: Jaroslav Tulach <ja...@apidesign.org>
AuthorDate: Wed Dec 23 06:24:11 2020 +0100

    Try harder to executeNow in asynchronous processors
---
 .../html/presenters/spi/test/GenericTCK.java       | 29 +++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTCK.java b/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTCK.java
index dedbc70..872ad98 100644
--- a/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTCK.java
+++ b/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTCK.java
@@ -20,6 +20,9 @@ package org.netbeans.html.presenters.spi.test;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import javax.script.ScriptException;
 import org.netbeans.html.boot.spi.Fn;
 import org.netbeans.html.json.tck.JavaScriptTCK;
 import org.netbeans.html.presenters.spi.ProtoPresenter;
@@ -36,7 +39,31 @@ final class GenericTCK extends JavaScriptTCK {
     public boolean executeNow(String script) throws Exception {
         Testing t = MAP.get(Fn.activePresenter());
         assertNotNull(t, "Testing framework found");
-        return t.sync ? t.eng.eval(script) != this : false;
+        if (t.sync) {
+            t.eng.eval(script);
+            return true;
+        } else {
+            CountDownLatch cdl = new CountDownLatch(1);
+            Exception[] error = { null };
+            boolean[] queueEntered = { false };
+            t.QUEUE.execute(() -> {
+                if (cdl.getCount() == 1) {
+                    try {
+                        queueEntered[0] = true;
+                        t.eng.eval(script);
+                    } catch (ScriptException ex) {
+                        error[0] = ex;
+                    } finally {
+                        cdl.countDown();
+                    }
+                }
+            });
+            cdl.await(3, TimeUnit.SECONDS);
+            if (error[0] != null) {
+                throw error[0];
+            }
+            return queueEntered[0];
+        }
     }
 
     public static Class[] tests() {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

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