1
0
This commit is contained in:
2024-11-14 13:36:37 +03:00
parent 5bae7a279b
commit 6a61a96a16
6 changed files with 82 additions and 59 deletions

View File

@@ -1,3 +1,4 @@
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import ru.lionarius.sync.MyCountDownLatch;
@@ -30,7 +31,7 @@ class MyCountDownLatchTest {
assertEquals(0, latch.getCount());
}
@Test
@RepeatedTest(20)
void testAwait() throws InterruptedException {
var latch = new MyCountDownLatch(2);
var threadFinished = new AtomicBoolean(false);
@@ -39,8 +40,7 @@ class MyCountDownLatchTest {
try {
latch.await();
threadFinished.set(true);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (InterruptedException ignored) {
}
});
@@ -58,6 +58,7 @@ class MyCountDownLatchTest {
}
@Test
@Timeout(value = 1000, unit = TimeUnit.MILLISECONDS)
void testMultipleThreads() throws InterruptedException {
final int THREAD_COUNT = 5;
var startLatch = new MyCountDownLatch(1);
@@ -76,8 +77,7 @@ class MyCountDownLatchTest {
Thread.sleep(100);
threadsFinished[index].set(true);
endLatch.countDown();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (InterruptedException ignored) {
}
}).start();
}
@@ -106,7 +106,6 @@ class MyCountDownLatchTest {
void testZeroCount() throws InterruptedException {
var latch = new MyCountDownLatch(0);
assertEquals(0, latch.getCount());
latch.await();
assertTrue(true);
assertTrue(latch.tryAwait());
}
}