You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
public class Counter {
private int count;
public void increment() { count++; }
public int getCount() { return count; }
}
Test class
public class CounterTest {
private Counter sut;
@Test
public void testThreading() {
AnnotatedTestRunner runner = new AnnotatedTestRunner();
runner.runTests(this.getClass(), Counter.class);
}
@ThreadedBefore
public void before() {
sut = new Counter();
}
@ThreadedMain
public void main() {
sut.increment();
}
@ThreadedSecondary
public void secondary() {
sut.increment();
}
@ThreadedAfter
public void after() {
assertEquals(sut.getCount(),2);
}
}
Expected result
Test fails.
Interweaving should allow for the result to be 1 due to race condition at counter++:
ThreadMain reads 0
ThreadSecondary reads 0
ThreadMain increments to 1
ThreadMain writes 1
ThreadSecondary increments to 1
ThreadSecondary writes 1
Final value for counter 1. Expected value being 2, that should make the test fail.
Actual result
Test passes.
Environment
<dependency>
<groupId>com.googlecode.thread-weaver</groupId>
<artifactId>threadweaver</artifactId>
<version>0.2</version>
</dependency>
$ java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
$ uname -a
Darwin hostname.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64
The text was updated successfully, but these errors were encountered:
A test that should fail but doesn't.
System under test
Test class
Expected result
Test fails.
Interweaving should allow for the result to be 1 due to race condition at
counter++
:Final value for counter 1. Expected value being 2, that should make the test fail.
Actual result
Test passes.
Environment
The text was updated successfully, but these errors were encountered: