test: (kinda) fix flaky test

deals_retry_deal_no_funds_test.go:TestDealsRetryLackOfFunds seems to be
flaky, sometimes it passes and sometimes it doesn't.
The first suspect for me was time.Sleep(), which I replaced with waiting
until a deal state where you can restart is reached.
This commit is contained in:
Nikola Divic 2022-02-11 21:56:28 +01:00
parent 94374aa93d
commit baee4a1576
2 changed files with 24 additions and 2 deletions

View File

@ -95,12 +95,11 @@ func TestDealsRetryLackOfFunds(t *testing.T) {
dp.FastRetrieval = true dp.FastRetrieval = true
dp.EpochPrice = abi.NewTokenAmount(62500000) // minimum asking price. dp.EpochPrice = abi.NewTokenAmount(62500000) // minimum asking price.
deal := dh.StartDeal(ctx, dp) deal := dh.StartDeal(ctx, dp)
dh.WaitUntilDataTransfer(ctx, deal)
propcid := *deal propcid := *deal
go func() { go func() {
time.Sleep(3 * time.Second)
kit.SendFunds(ctx, t, minerFullNode, publishStorageDealKey.Address, types.FromFil(1)) kit.SendFunds(ctx, t, minerFullNode, publishStorageDealKey.Address, types.FromFil(1))
err := miner.MarketRetryPublishDeal(ctx, propcid) err := miner.MarketRetryPublishDeal(ctx, propcid)

View File

@ -134,6 +134,29 @@ func (dh *DealHarness) StartDeal(ctx context.Context, dealParams api.StartDealPa
return dealProposalCid return dealProposalCid
} }
func (dh *DealHarness) WaitUntilDataTransfer(ctx context.Context, deal *cid.Cid) {
loop:
for {
di, err := dh.client.ClientGetDealInfo(ctx, *deal)
if err != nil {
dh.t.Fatal("can't fetch deal info")
}
switch di.State {
case storagemarket.StorageDealProposalRejected:
dh.t.Fatal("deal rejected")
case storagemarket.StorageDealFailing:
dh.t.Fatal("deal failed")
case storagemarket.StorageDealError:
dh.t.Fatal("deal errored")
case storagemarket.StorageDealStartDataTransfer:
break loop
}
time.Sleep(time.Millisecond * 100)
}
}
// WaitDealSealed waits until the deal is sealed. // WaitDealSealed waits until the deal is sealed.
func (dh *DealHarness) WaitDealSealed(ctx context.Context, deal *cid.Cid, noseal, noSealStart bool, cb func()) { func (dh *DealHarness) WaitDealSealed(ctx context.Context, deal *cid.Cid, noseal, noSealStart bool, cb func()) {
loop: loop: