Created
December 4, 2015 21:45
-
-
Save jentfoo/742806ef3c5395e910ea to your computer and use it in GitHub Desktop.
threadly schedule 4.4.0 regression unit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void scheduleLaterThenSoonerTest() { | |
// This test is focused around the scheduling defect fixed in 4.4.1 | |
// The condition hit was where we would park for one scheduled task, then a future task | |
// would not get executed in time because the first parked thread was not woken up | |
final PriorityScheduler scheduler = new PriorityScheduler(2); | |
try { | |
// schedule one task a ways out | |
scheduler.schedule(DoNothingRunnable.instance(), 1000 * 60 * 10); | |
// ensure first thread has blocked | |
new TestCondition() { | |
@Override | |
public boolean get() { | |
return scheduler.workerPool.idleWorker.get() != null; | |
} | |
}.blockTillTrue(); | |
// start second thread | |
scheduler.prestartAllThreads(); | |
// ensure second thread has blocked | |
new TestCondition() { | |
@Override | |
public boolean get() { | |
return scheduler.workerPool.idleWorker.get().nextIdleWorker != null; | |
} | |
}.blockTillTrue(); | |
// schedule soon to run task | |
TestRunnable tr = new TestRunnable(); | |
scheduler.schedule(tr, 10); | |
tr.blockTillStarted(1000); | |
} finally { | |
scheduler.shutdownNow(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment