Skip to content

Commit

Permalink
test: (kinda) fix flaky test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheDivic committed Feb 11, 2022
1 parent 94374aa commit baee4a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 1 addition & 2 deletions itests/deals_retry_deal_no_funds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ func TestDealsRetryLackOfFunds(t *testing.T) {
dp.FastRetrieval = true
dp.EpochPrice = abi.NewTokenAmount(62500000) // minimum asking price.
deal := dh.StartDeal(ctx, dp)
dh.WaitUntilDataTransfer(ctx, deal)

propcid := *deal

go func() {
time.Sleep(3 * time.Second)

kit.SendFunds(ctx, t, minerFullNode, publishStorageDealKey.Address, types.FromFil(1))

err := miner.MarketRetryPublishDeal(ctx, propcid)
Expand Down
23 changes: 23 additions & 0 deletions itests/kit/deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ func (dh *DealHarness) StartDeal(ctx context.Context, dealParams api.StartDealPa
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.
func (dh *DealHarness) WaitDealSealed(ctx context.Context, deal *cid.Cid, noseal, noSealStart bool, cb func()) {
loop:
Expand Down

0 comments on commit baee4a1

Please sign in to comment.