Skip to content

Commit

Permalink
Merge pull request #6733 from alyokaz/refactor-takebuybtcoffertest
Browse files Browse the repository at this point in the history
Refactor TakeBuyBTCOfferTest to replace sleep with loops
  • Loading branch information
alejandrogarcia83 authored Jul 6, 2023
2 parents ff44e18 + 03b205a commit 9d52cfe
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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.
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);
Expand Down

0 comments on commit 9d52cfe

Please sign in to comment.