Commit b0e05326 authored by Karolina Soltys's avatar Karolina Soltys Committed by Commit Bot

[scheduler] Fixing bug in NativePostTaskTest.

Bug: 938316
Change-Id: I442d2adcf949227f91a1111921d609d908670953
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1503736
Commit-Queue: Karolina Soltys <ksolt@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarAlex Clarke <alexclarke@chromium.org>
Auto-Submit: Karolina Soltys <ksolt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638116}
parent 642f2e63
...@@ -61,13 +61,10 @@ public class NativePostTaskTest { ...@@ -61,13 +61,10 @@ public class NativePostTaskTest {
} }
} }
}); });
synchronized (lock) { synchronized (lock) {
try { while (!taskExecuted.get()) {
while (!taskExecuted.get()) { lock.wait();
lock.wait();
}
} catch (InterruptedException ie) {
ie.printStackTrace();
} }
} }
} }
...@@ -88,16 +85,12 @@ public class NativePostTaskTest { ...@@ -88,16 +85,12 @@ public class NativePostTaskTest {
Assert.assertFalse(taskExecuted.get()); Assert.assertFalse(taskExecuted.get());
startNativeScheduler(); startNativeScheduler();
try { // The task should now be scheduled at some point after the delay, so the test shouldn't
// The task should now be scheduled at some point after the delay, so the test shouldn't // time out.
// time out. synchronized (lock) {
synchronized (lock) { while (!taskExecuted.get()) {
while (!taskExecuted.get()) { lock.wait();
lock.wait();
}
} }
} catch (InterruptedException ie) {
ie.printStackTrace();
} }
} }
...@@ -169,9 +162,9 @@ public class NativePostTaskTest { ...@@ -169,9 +162,9 @@ public class NativePostTaskTest {
public void testCreateTaskRunnerMigrationToNative() throws Exception { public void testCreateTaskRunnerMigrationToNative() throws Exception {
final Object lock = new Object(); final Object lock = new Object();
final AtomicBoolean taskExecuted = new AtomicBoolean(); final AtomicBoolean taskExecuted = new AtomicBoolean();
TaskRunner taskQueue = PostTask.createSequencedTaskRunner(new TaskTraits()); TaskRunner taskQueue = PostTask.createTaskRunner(new TaskTraits());
taskQueue.postDelayedTask(new Runnable() { postRepeatingTaskAndStartNativeSchedulerThenWaitForTaskToRun(taskQueue, new Runnable() {
@Override @Override
public void run() { public void run() {
synchronized (lock) { synchronized (lock) {
...@@ -179,23 +172,18 @@ public class NativePostTaskTest { ...@@ -179,23 +172,18 @@ public class NativePostTaskTest {
lock.notify(); lock.notify();
} }
} }
}, 1); });
taskQueue.destroy();
// We verify that the task didn't get scheduled before the native scheduler is initialised
Assert.assertFalse(taskExecuted.get());
startNativeScheduler();
try { try {
// The task should now be scheduled at some point after the delay, so the test shouldn't // The task should run at some point after the migration, so the test shouldn't
// time out. // time out.
synchronized (lock) { synchronized (lock) {
while (!taskExecuted.get()) { while (!taskExecuted.get()) {
lock.wait(); lock.wait();
} }
} }
} catch (InterruptedException ie) { } finally {
ie.printStackTrace(); taskQueue.destroy();
} }
} }
...@@ -258,12 +246,8 @@ public class NativePostTaskTest { ...@@ -258,12 +246,8 @@ public class NativePostTaskTest {
nativeSchedulerStarted.set(true); nativeSchedulerStarted.set(true);
synchronized (lock) { synchronized (lock) {
try { while (!taskRun.get()) {
while (!taskRun.get()) { lock.wait();
lock.wait();
}
} catch (InterruptedException ie) {
ie.printStackTrace();
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment