Skip to content

Commit 56acdb2

Browse files
committed
[JAVA-8353] Wait longer for the threads to finish
1 parent 56f87cb commit 56acdb2

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.baeldung.exceptions.illegalmonitorstate;
22

3-
import org.junit.jupiter.api.Test;
4-
5-
import java.time.Duration;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertNull;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
67

7-
import static org.junit.jupiter.api.Assertions.*;
8+
import org.junit.jupiter.api.Test;
89

910
public class IllegalMonitorStateExceptionUnitTest {
1011

@@ -20,11 +21,11 @@ void whenSyncSenderAndSyncReceiverAreUsed_thenIllegalMonitorExceptionShouldNotBe
2021
Thread senderThread = new Thread(sender, "sender-thread");
2122
senderThread.start();
2223

23-
senderThread.join(1000);
24-
receiverThread.join(1000);
24+
// we need to wait for the sender and receiver threads to finish
25+
senderThread.join(10_000);
26+
receiverThread.join(10_000);
2527

26-
// we need to wait for enough time so that sender has had a chance to send the data
27-
assertTimeout(Duration.ofSeconds(10), () -> assertEquals("test", receiver.getMessage()));
28+
assertEquals("test", receiver.getMessage());
2829
assertFalse(sender.hasIllegalMonitorStateExceptionOccurred());
2930
assertFalse(receiver.hasIllegalMonitorStateExceptionOccurred());
3031
}

0 commit comments

Comments
 (0)