Skip to content

Commit cd449e3

Browse files
committed
Disable spurious notifies for testWaitWithoutNotify.
1 parent fc6d808 commit cd449e3

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

core/src/test/java/org/pastalab/fray/core/test/FrayRunner.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414

1515
public class FrayRunner {
1616
public Throwable runWithFifo(Function0<Unit> exec) {
17-
return runWithScheduler(exec, new FifoScheduler(), 1);
17+
return runWithScheduler(exec, new FifoScheduler(), 1, new ControlledRandom());
1818
}
1919

2020
public Throwable runWithPOS(Function0<Unit> exec) {
21-
return runWithScheduler(exec, new POSScheduler(), 10000);
21+
return runWithScheduler(exec, new POSScheduler(), 10000, new ControlledRandom());
2222
}
2323

24-
public Throwable runWithScheduler(Function0<Unit> exec, Scheduler scheduler, int iter) {
25-
return buildRunner(exec, scheduler, iter).run();
24+
public Throwable runWithScheduler(Function0<Unit> exec, Scheduler scheduler, int iter, ControlledRandom random) {
25+
return buildRunner(exec, scheduler, iter, random).run();
2626
}
2727

28-
public TestRunner buildRunner(Function0<Unit> exec, Scheduler scheduler, int iter) {
28+
public TestRunner buildRunner(Function0<Unit> exec, Scheduler scheduler, int iter, ControlledRandom random) {
2929
Configuration config = new Configuration(
3030
new ExecutionInfo(
3131
new LambdaExecutor(() -> {
@@ -40,7 +40,7 @@ public TestRunner buildRunner(Function0<Unit> exec, Scheduler scheduler, int ite
4040
"/tmp/report",
4141
iter,
4242
scheduler,
43-
new ControlledRandom(),
43+
random,
4444
true,
4545
false,
4646
true,

core/src/test/java/org/pastalab/fray/core/test/primitives/ConcurrentHashmapTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void testConcurrentHashMapDifferentExecutionPath() {
5050
map.put(new DeterministicHashCodeObject(1014958949), i.getAndIncrement());
5151
return null;
5252
};
53-
TestRunner runner = buildRunner(task, new FifoScheduler(), 1);
53+
TestRunner runner = buildRunner(task, new FifoScheduler(), 1, new ControlledRandom());
5454
ScheduleRecorder recorder = new ScheduleRecorder();
5555
runner.getConfig().getScheduleObservers().add(recorder);
5656
runner.run();
@@ -65,7 +65,7 @@ public void testConcurrentHashMapDifferentExecutionPath() {
6565
map.put(new DeterministicHashCodeObject(-507498936), i.getAndIncrement());
6666
return null;
6767
};
68-
TestRunner runner2 = buildRunner(task, new FifoScheduler(), 1);
68+
TestRunner runner2 = buildRunner(task, new FifoScheduler(), 1, new ControlledRandom());
6969
ScheduleRecorder recorder2 = new ScheduleRecorder();
7070
runner2.getConfig().getScheduleObservers().add(recorder2);
7171
runner2.run();
@@ -90,7 +90,7 @@ public void testConcurrentHashMapSameExecutionPath() {
9090
map.put(o, i.getAndIncrement());
9191
return null;
9292
};
93-
TestRunner runner = buildRunner(task, new FifoScheduler(), 1);
93+
TestRunner runner = buildRunner(task, new FifoScheduler(), 1, new ControlledRandom());
9494
ScheduleRecorder recorder = new ScheduleRecorder();
9595
runner.getConfig().getScheduleObservers().add(recorder);
9696
runner.run();
@@ -112,7 +112,7 @@ public void testConcurrentHashMapSameExecutionPath() {
112112
map.put(o, i.getAndIncrement());
113113
return null;
114114
};
115-
TestRunner runner2 = buildRunner(task, new FifoScheduler(), 1);
115+
TestRunner runner2 = buildRunner(task, new FifoScheduler(), 1, new ControlledRandom());
116116
runner2.getConfig()
117117
.setRandomnessProvider(new ControlledRandom(randomSource.getIntegers(),
118118
randomSource.getDoubles(), new Random()));

core/src/test/java/org/pastalab/fray/core/test/primitives/IntStreamTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.pastalab.fray.core.test.primitives;
22

33
import org.junit.jupiter.api.Test;
4+
import org.pastalab.fray.core.randomness.ControlledRandom;
45
import org.pastalab.fray.core.scheduler.POSScheduler;
56
import org.pastalab.fray.core.test.FrayRunner;
67

@@ -19,7 +20,7 @@ public void test() {
1920
assert(x.get() != 10);
2021
return null;
2122
}, new POSScheduler(),
22-
1000000).run();
23+
1000000, new ControlledRandom()).run();
2324
assertTrue(result instanceof AssertionError);
2425
}
2526

core/src/test/java/org/pastalab/fray/core/test/primitives/WaitTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package org.pastalab.fray.core.test.primitives;
22

33
import org.junit.jupiter.api.Test;
4+
import org.pastalab.fray.core.randomness.ControlledRandom;
5+
import org.pastalab.fray.core.scheduler.FifoScheduler;
46
import org.pastalab.fray.core.test.FrayRunner;
57
import org.pastalab.fray.runtime.DeadlockException;
68

9+
import java.util.ArrayList;
10+
import java.util.Random;
711
import java.util.concurrent.CountDownLatch;
812
import java.util.concurrent.atomic.AtomicBoolean;
913

@@ -26,7 +30,11 @@ public void testWaitWithoutMonitorLock() {
2630

2731
@Test
2832
public void testWaitWithoutNotify() {
29-
Throwable result = runWithFifo(() -> {
33+
ArrayList<Integer> randInts = new ArrayList<>();
34+
randInts.add(1);
35+
randInts.add(1);
36+
randInts.add(1);
37+
Throwable result = runWithScheduler(() -> {
3038
try {
3139
synchronized (this) {
3240
wait();
@@ -35,7 +43,7 @@ public void testWaitWithoutNotify() {
3543
throw new RuntimeException(e);
3644
}
3745
return null;
38-
});
46+
}, new FifoScheduler(), 1, new ControlledRandom(randInts, new ArrayList<>(), new Random()));
3947
assertInstanceOf(DeadlockException.class, result);
4048
}
4149

0 commit comments

Comments
 (0)