Merge pull request #4608 from filecoin-project/fix/flaky-TestCLIDealFlow

Fix flaky TestCLIDealFlow
This commit is contained in:
Łukasz Magiera 2020-10-27 12:07:02 +01:00 committed by GitHub
commit 1db69acbc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 8 deletions

View File

@ -48,7 +48,7 @@ func TestPaymentChannels(t *testing.T) {
receiverAddr := addrs[1]
// Create mock CLI
mockCLI := clitest.NewMockCLI(t, Commands)
mockCLI := clitest.NewMockCLI(ctx, t, Commands)
creatorCLI := mockCLI.Client(paymentCreator.ListenAddr)
receiverCLI := mockCLI.Client(paymentReceiver.ListenAddr)
@ -99,7 +99,7 @@ func TestPaymentChannelStatus(t *testing.T) {
receiverAddr := addrs[1]
// Create mock CLI
mockCLI := clitest.NewMockCLI(t, Commands)
mockCLI := clitest.NewMockCLI(ctx, t, Commands)
creatorCLI := mockCLI.Client(paymentCreator.ListenAddr)
// creator: paych status-by-from-to <creator> <receiver>
@ -179,7 +179,7 @@ func TestPaymentChannelVouchers(t *testing.T) {
receiverAddr := addrs[1]
// Create mock CLI
mockCLI := clitest.NewMockCLI(t, Commands)
mockCLI := clitest.NewMockCLI(ctx, t, Commands)
creatorCLI := mockCLI.Client(paymentCreator.ListenAddr)
receiverCLI := mockCLI.Client(paymentReceiver.ListenAddr)
@ -310,7 +310,7 @@ func TestPaymentChannelVoucherCreateShortfall(t *testing.T) {
receiverAddr := addrs[1]
// Create mock CLI
mockCLI := clitest.NewMockCLI(t, Commands)
mockCLI := clitest.NewMockCLI(ctx, t, Commands)
creatorCLI := mockCLI.Client(paymentCreator.ListenAddr)
// creator: paych add-funds <creator> <receiver> <amount>

View File

@ -11,6 +11,8 @@ import (
"testing"
"time"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api/test"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
@ -25,7 +27,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode)
defer cancel()
// Create mock CLI
mockCLI := NewMockCLI(t, cmds)
mockCLI := NewMockCLI(ctx, t, cmds)
clientCLI := mockCLI.Client(clientNode.ListenAddr)
// Get the miner address
@ -74,7 +76,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode)
// Wait for provider to start sealing deal
dealStatus := ""
for dealStatus != "StorageDealSealing" {
for {
// client list-deals
out = clientCLI.RunCmd("client", "list-deals")
fmt.Println("list-deals:\n", out)
@ -88,6 +90,9 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode)
}
dealStatus = parts[3]
fmt.Println(" Deal status:", dealStatus)
if dealComplete(t, dealStatus) {
break
}
time.Sleep(time.Second)
}
@ -101,3 +106,14 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode)
fmt.Println("retrieve:\n", out)
require.Regexp(t, regexp.MustCompile("Success"), out)
}
func dealComplete(t *testing.T, dealStatus string) bool {
switch dealStatus {
case "StorageDealFailing", "StorageDealError":
t.Fatal(xerrors.Errorf("Storage deal failed with status: " + dealStatus))
case "StorageDealStaged", "StorageDealSealing", "StorageDealActive", "StorageDealExpired", "StorageDealSlashed":
return true
}
return false
}

View File

@ -2,6 +2,7 @@ package test
import (
"bytes"
"context"
"flag"
"strings"
"testing"
@ -18,7 +19,7 @@ type MockCLI struct {
out *bytes.Buffer
}
func NewMockCLI(t *testing.T, cmds []*lcli.Command) *MockCLI {
func NewMockCLI(ctx context.Context, t *testing.T, cmds []*lcli.Command) *MockCLI {
// Create a CLI App with an --api-url flag so that we can specify which node
// the command should be executed against
app := &lcli.App{
@ -36,6 +37,7 @@ func NewMockCLI(t *testing.T, cmds []*lcli.Command) *MockCLI {
app.Setup()
cctx := lcli.NewContext(app, &flag.FlagSet{}, nil)
cctx.Context = ctx
return &MockCLI{t: t, cmds: cmds, cctx: cctx, out: &out}
}

View File

@ -18,7 +18,7 @@ func RunMultisigTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNod
ctx := context.Background()
// Create mock CLI
mockCLI := NewMockCLI(t, cmds)
mockCLI := NewMockCLI(ctx, t, cmds)
clientCLI := mockCLI.Client(clientNode.ListenAddr)
// Create some wallets on the node to use for testing multisig