From b0528f157aaddc71474b9c23e006e6eba760df58 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sat, 26 Oct 2019 16:18:59 -0700 Subject: [PATCH] Improve timeout tracking for expressions --- .../com/sk89q/worldedit/internal/expression/Expression.java | 4 ++++ worldedit-core/src/test/resources/junit-platform.properties | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java index 9bca48e12..147378934 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java @@ -37,6 +37,7 @@ import java.lang.invoke.MethodHandle; import java.util.List; import java.util.Objects; import java.util.Stack; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -141,6 +142,7 @@ public class Expression { } private double evaluateRootTimed(int timeout) throws EvaluationException { + CountDownLatch startLatch = new CountDownLatch(1); Request request = Request.request(); Future result = evalThread.submit(() -> { Request local = Request.request(); @@ -148,12 +150,14 @@ public class Expression { local.setWorld(request.getWorld()); local.setEditSession(request.getEditSession()); try { + startLatch.countDown(); return Expression.this.evaluateRoot(); } finally { Request.reset(); } }); try { + startLatch.await(); return result.get(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/worldedit-core/src/test/resources/junit-platform.properties b/worldedit-core/src/test/resources/junit-platform.properties index ee7c4fad3..31bfedd9e 100644 --- a/worldedit-core/src/test/resources/junit-platform.properties +++ b/worldedit-core/src/test/resources/junit-platform.properties @@ -2,4 +2,4 @@ junit.jupiter.execution.parallel.enabled=true junit.jupiter.execution.parallel.mode.default=concurrent junit.jupiter.execution.parallel.mode.classes.default=same_thread junit.jupiter.execution.parallel.config.strategy=dynamic -junit.jupiter.execution.parallel.config.dynamic.factor=4 +junit.jupiter.execution.parallel.config.dynamic.factor=1