Refactor TakeBuyBTCOfferTest to replace sleep with loops

Replace the use of Thread.sleep in the tests with loops
This commit is contained in:
AllyKaz 2023-06-14 20:00:15 +01:00
parent c8c256f958
commit 03b205a597
No known key found for this signature in database
GPG Key ID: 9153AC3079E198F8

View File

@ -19,8 +19,13 @@ package bisq.apitest.method.trade;
import bisq.core.payment.PaymentAccount;
import bisq.proto.grpc.OfferInfo;
import io.grpc.StatusRuntimeException;
import java.util.List;
import java.util.concurrent.TimeoutException;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Disabled;
@ -71,19 +76,34 @@ public class TakeBuyBTCOfferTest extends AbstractTradeTest {
// Wait for Alice's AddToOfferBook task.
// Wait times vary; my logs show >= 2-second delay.
sleep(3_000); // TODO loop instead of hard code a wait time
var alicesUsdOffers = aliceClient.getMyOffersSortedByDate(BUY.name(), USD);
var timeout = System.currentTimeMillis() + 3000;
while (bobClient.getOffersSortedByDate(USD, true).size() < 1) {
sleep(100);
if (System.currentTimeMillis() > timeout)
fail(new TimeoutException("Timed out waiting for Offer to be added to OfferBook"));
}
List<OfferInfo> alicesUsdOffers = aliceClient.getMyOffersSortedByDate(BUY.name(), USD);
assertEquals(1, alicesUsdOffers.size());
PaymentAccount bobsUsdAccount = createDummyF2FAccount(bobClient, "US");
var ignoredTakeOfferAmountParam = 0L;
var trade = takeAlicesOffer(offerId,
bobsUsdAccount.getId(),
TRADE_FEE_CURRENCY_CODE,
ignoredTakeOfferAmountParam,
false);
sleep(2_500); // Allow available offer to be removed from offer book.
// Allow available offer to be removed from offer book.
timeout = System.currentTimeMillis() + 2500;
do {
alicesUsdOffers = aliceClient.getMyOffersSortedByDate(BUY.name(), USD);
sleep(100);
if (System.currentTimeMillis() > timeout)
fail(new TimeoutException("Timed out waiting for Offer to be removed from OfferBook"));
} while (alicesUsdOffers.size() > 0);
assertEquals(0, alicesUsdOffers.size());
trade = bobClient.getTrade(tradeId);