Skip to content

Commit

Permalink
remove Thread.sleep from test (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored Aug 22, 2023
1 parent ae67213 commit 465645c
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.concurrent.AsyncCompletion;
import org.apache.tuweni.concurrent.CompletableAsyncCompletion;
import org.apache.tuweni.crypto.Hash;
import org.apache.tuweni.junit.BouncyCastleExtension;

Expand Down Expand Up @@ -39,13 +41,18 @@ private static class MockMessageSender implements MessageSender {
Bytes hash;
Bytes payload;

CompletableAsyncCompletion waitForMessageSent;

@Override
public void sendMessage(
Verb verb, Map<String, Bytes> attributes, Peer peer, Bytes hash, Bytes payload) {
this.verb = verb;
this.peer = peer;
this.hash = hash;
this.payload = payload;
if (waitForMessageSent != null) {
waitForMessageSent.complete();
}
}
}

Expand Down Expand Up @@ -257,6 +264,7 @@ void receiveFullMessageFromEagerPeerThenPartialMessageFromLazyPeer() {
void receivePartialMessageFromLazyPeerAndNoFullMessage() throws Exception {
EphemeralPeerRepository repo = new EphemeralPeerRepository();
MockMessageSender messageSender = new MockMessageSender();
messageSender.waitForMessageSent = AsyncCompletion.incomplete();
State state =
new State(
repo,
Expand All @@ -274,7 +282,7 @@ void receivePartialMessageFromLazyPeerAndNoFullMessage() throws Exception {
repo.moveToLazy(lazyPeer);
Bytes message = Bytes32.random();
state.receiveIHaveMessage(lazyPeer, message);
Thread.sleep(200);
messageSender.waitForMessageSent.join();
assertEquals(message, messageSender.hash);
assertEquals(lazyPeer, messageSender.peer);
assertEquals(MessageSender.Verb.GRAFT, messageSender.verb);
Expand Down

0 comments on commit 465645c

Please sign in to comment.