Skip to content

Commit

Permalink
Merge pull request #1481 from jsign/jsign/testnet3/DoubleTestAPIDealF…
Browse files Browse the repository at this point in the history
…lowFAIL

Double Deal Flow test
  • Loading branch information
arajasek authored Apr 23, 2020
2 parents 70f21d6 + 1f2b767 commit 58fe29d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 14 deletions.
67 changes: 55 additions & 12 deletions api/test/deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,42 @@ func TestDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration, carExport
}
time.Sleep(time.Second)

data := make([]byte, 600)
rand.New(rand.NewSource(5)).Read(data)
mine := true
done := make(chan struct{})
go func() {
defer close(done)
for mine {
time.Sleep(blocktime)
if err := sn[0].MineOne(ctx); err != nil {
t.Error(err)
}
}
}()

r := bytes.NewReader(data)
fcid, err := client.ClientImportLocal(ctx, r)
makeDeal(t, ctx, 6, client, miner, carExport)

mine = false
fmt.Println("shutting down mining")
<-done
}

func TestDoubleDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration) {
os.Setenv("BELLMAN_NO_GPU", "1")

ctx := context.Background()
n, sn := b(t, 1, []int{0})
client := n[0].FullNode.(*impl.FullNodeAPI)
miner := sn[0]

addrinfo, err := client.NetAddrsListen(ctx)
if err != nil {
t.Fatal(err)
}

maddr, err := miner.ActorAddress(ctx)
if err != nil {
if err := miner.NetConnect(ctx, addrinfo); err != nil {
t.Fatal(err)
}

fmt.Println("FILE CID: ", fcid)
time.Sleep(time.Second)

mine := true
done := make(chan struct{})
Expand All @@ -78,6 +99,32 @@ func TestDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration, carExport
}
}
}()

makeDeal(t, ctx, 6, client, miner, false)
makeDeal(t, ctx, 7, client, miner, false)

mine = false
fmt.Println("shutting down mining")
<-done
}

func makeDeal(t *testing.T, ctx context.Context, rseed int, client *impl.FullNodeAPI, miner TestStorageNode, carExport bool) {
data := make([]byte, 1600)
rand.New(rand.NewSource(6)).Read(data)

r := bytes.NewReader(data)
fcid, err := client.ClientImportLocal(ctx, r)
if err != nil {
t.Fatal(err)
}

maddr, err := miner.ActorAddress(ctx)
if err != nil {
t.Fatal(err)
}

fmt.Println("FILE CID: ", fcid)

addr, err := client.WalletDefaultAddress(ctx)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -184,8 +231,4 @@ loop:
if !bytes.Equal(rdata, data) {
t.Fatal("wrong data retrieved")
}

mine = false
fmt.Println("shutting down mining")
<-done
}
8 changes: 6 additions & 2 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,15 @@ func TestAPIDealFlow(t *testing.T) {
logging.SetLogLevel("sub", "ERROR")
logging.SetLogLevel("storageminer", "ERROR")

test.TestDealFlow(t, mockSbBuilder, 10*time.Millisecond, false)

t.Run("TestDealFlow", func(t *testing.T) {
test.TestDealFlow(t, mockSbBuilder, 10*time.Millisecond, false)
})
t.Run("WithExportedCAR", func(t *testing.T) {
test.TestDealFlow(t, mockSbBuilder, 10*time.Millisecond, true)
})
t.Run("TestDoubleDealFlow", func(t *testing.T) {
test.TestDoubleDealFlow(t, mockSbBuilder, 10*time.Millisecond)
})
}

func TestAPIDealFlowReal(t *testing.T) {
Expand Down

0 comments on commit 58fe29d

Please sign in to comment.