diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-10-11 12:00:04 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-10-11 12:00:04 +0200 |
commit | 09701a9de35ffe55b9b7190133bddbb9cdbbc03b (patch) | |
tree | 4cfd44432b9f3afaac332419ef91d5b8b98a1a76 /jdisc_core | |
parent | 84cbeace33cdc2308fe42e8a8fe4a74411492202 (diff) |
- Use notify to reduce runtime from 1m10s to 12s for unit tests.
- Use join to ensure we have proper shutdown. Revealed an almost eternal loop in unit test.
- Ensure that we stop looking for things to time out when there is nothing left.
Diffstat (limited to 'jdisc_core')
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/core/ScheduledQueue.java | 3 | ||||
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/core/TimeoutManagerImpl.java | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ScheduledQueue.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ScheduledQueue.java index 397271d0b48..09483a7c7e5 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ScheduledQueue.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ScheduledQueue.java @@ -35,8 +35,9 @@ class ScheduledQueue { if (slots[NUM_SLOTS] == null && currentTimeMillis < nextTick) { return; } + int queueSize = queueSize() + out.size(); drainTo(NUM_SLOTS, 0, out); - for (int i = 0; currentTimeMillis >= nextTick; i++, nextTick += MILLIS_PER_SLOT) { + for (int i = 0; currentTimeMillis >= nextTick && (queueSize > out.size()); i++, nextTick += MILLIS_PER_SLOT) { if (i < NUM_SLOTS_UNDILATED) { if (++currSlot >= NUM_SLOTS) { currSlot = 0; diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/TimeoutManagerImpl.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/TimeoutManagerImpl.java index bb1ffce1c86..d7b652b80f7 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/TimeoutManagerImpl.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/TimeoutManagerImpl.java @@ -53,7 +53,13 @@ public class TimeoutManagerImpl { } public void shutdown() { - done.set(true); + synchronized (done) { + done.set(true); + done.notify(); + } + try { + thread.join(); + } catch (InterruptedException e) {} } public RequestHandler manageHandler(RequestHandler handler) { |