Skip to content

Commit

Permalink
Add tests for declaring the global read-write lock on nested tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Oct 3, 2024
1 parent 2fa0d2c commit 7cf8ec4
Showing 1 changed file with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ void runsIsolatedTestsLastToMaximizeParallelism() {
}

@ParameterizedTest
@ValueSource(classes = { IsolatedMethodFirstTestCase.class, IsolatedMethodLastTestCase.class })
@ValueSource(classes = { IsolatedMethodFirstTestCase.class, IsolatedMethodLastTestCase.class,
IsolatedNestedMethodFirstTestCase.class, IsolatedNestedMethodLastTestCase.class })
void canRunTestsIsolatedFromEachOtherWhenDeclaredOnMethodLevel(Class<?> testClass) {
List<Event> events = executeConcurrentlySuccessfully(1, testClass).list();

Expand Down Expand Up @@ -410,6 +411,72 @@ void test2() throws InterruptedException {
}
}

@ExtendWith(ThreadReporter.class)
static class IsolatedNestedMethodFirstTestCase {

static AtomicInteger sharedResource;
static CountDownLatch countDownLatch;

@BeforeAll
static void initialize() {
sharedResource = new AtomicInteger();
countDownLatch = new CountDownLatch(2);
}

@Nested
class Test1 {

@Test
@ResourceLock(value = GLOBAL_KEY, mode = READ_WRITE) // effectively @Isolated
void test1() throws InterruptedException {
incrementBlockAndCheck(sharedResource, countDownLatch);
}
}

@Nested
class Test2 {

@Test
@ResourceLock(value = "b", mode = READ_WRITE)
void test2() throws InterruptedException {
incrementBlockAndCheck(sharedResource, countDownLatch);
}
}
}

@ExtendWith(ThreadReporter.class)
static class IsolatedNestedMethodLastTestCase {

static AtomicInteger sharedResource;
static CountDownLatch countDownLatch;

@BeforeAll
static void initialize() {
sharedResource = new AtomicInteger();
countDownLatch = new CountDownLatch(2);
}

@Nested
class Test1 {

@Test
@ResourceLock(value = "b", mode = READ_WRITE)
void test1() throws InterruptedException {
incrementBlockAndCheck(sharedResource, countDownLatch);
}
}

@Nested
class Test2 {

@Test
@ResourceLock(value = GLOBAL_KEY, mode = READ_WRITE) // effectively @Isolated
void test2() throws InterruptedException {
incrementBlockAndCheck(sharedResource, countDownLatch);
}
}
}

static class IndependentClasses {
static AtomicInteger sharedResource = new AtomicInteger();
static CountDownLatch countDownLatch = new CountDownLatch(4);
Expand Down

0 comments on commit 7cf8ec4

Please sign in to comment.