Skip to content

Commit

Permalink
#39 infinity loop
Browse files Browse the repository at this point in the history
  • Loading branch information
l3r8yJ committed Dec 1, 2022
1 parent 8054d05 commit 17fdf06
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/test/java/com/yegor256/tojos/MnSynchronizedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class MnSynchronizedTest {
*/
private ExecutorService executor;

/**
* The latch.
*/
private CountDownLatch latch;

@BeforeEach
Expand All @@ -71,22 +74,15 @@ final void setUp(@TempDir final Path temp) {
this.latch = new CountDownLatch(1);
}

/**
* Thread-safety test.
* In this test, we check the number of changes in MnSynchronized mono.
* It should be equal to the sum of the arithmetic progression over the number of threads.
*
* @throws InterruptedException When fails
*/
@Test
final void concurrentScenario() throws InterruptedException {
final Collection<Map<String, String>> addition = rowsByThreads();
final Collection<Map<String, String>> additional = rowsByThreads();
for (int trds = 1; trds <= MnSynchronizedTest.THREADS; ++trds) {
this.executor.submit(
() -> {
this.latch.await();
final Collection<Map<String, String>> increased = this.shared.read();
increased.addAll(addition);
increased.addAll(additional);
this.shared.write(increased);
return this.shared.read().size();
}
Expand Down

0 comments on commit 17fdf06

Please sign in to comment.