From 6e13e3f88ca4990136635667dd63afa900320615 Mon Sep 17 00:00:00 2001 From: AllyKaz Date: Wed, 14 Jun 2023 20:00:15 +0100 Subject: [PATCH] Refactor TakeBuyBTCOfferTest to replace sleep with loops Replace the use of Thread.sleep in the tests with loops --- .../method/trade/TakeBuyBTCOfferTest.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java index 4872c21032b..e0431bc8c8f 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java @@ -19,8 +19,13 @@ 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 void testTakeAlicesBuyOffer(final TestInfo testInfo) { // 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 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. - alicesUsdOffers = aliceClient.getMyOffersSortedByDate(BUY.name(), USD); + + // 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);