some baseline cleanup
1. Miners wait for all client's signal to stop mining 2. Miners don't care about client addresses 3. Moved collect methods to node.go
This commit is contained in:
parent
5cccc81abf
commit
58923fe2ff
@ -22,7 +22,6 @@ import (
|
||||
dstest "github.com/ipfs/go-merkledag/test"
|
||||
unixfile "github.com/ipfs/go-unixfs/file"
|
||||
"github.com/ipld/go-car"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
)
|
||||
|
||||
// This is the basline test; Filecoin 101.
|
||||
@ -68,14 +67,6 @@ func runBaselineMiner(t *TestEnvironment) error {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
addrs, err := collectClientsAddrs(t, ctx, t.IntParam("clients"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t.RecordMessage("got %v client addrs", len(addrs))
|
||||
|
||||
// mine / stop mining
|
||||
mine := true
|
||||
done := make(chan struct{})
|
||||
@ -86,7 +77,7 @@ func runBaselineMiner(t *TestEnvironment) error {
|
||||
//t.RecordMessage("mine one block")
|
||||
|
||||
// wait and synchronise
|
||||
if err := miner.MineOne(ctx, func(bool) {
|
||||
if err := miner.MineOne(context.TODO(), func(bool) {
|
||||
// after a block is mined
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
@ -94,8 +85,9 @@ func runBaselineMiner(t *TestEnvironment) error {
|
||||
}
|
||||
}()
|
||||
|
||||
// wait for a signa to stop mining
|
||||
err = <-t.SyncClient.MustBarrier(ctx, stateStopMining, 1).C
|
||||
// wait for a signal from all clients to stop mining
|
||||
clients := t.IntParam("clients")
|
||||
err = <-t.SyncClient.MustBarrier(context.Background(), stateStopMining, clients).C
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -104,7 +96,7 @@ func runBaselineMiner(t *TestEnvironment) error {
|
||||
t.RecordMessage("shutting down mining")
|
||||
<-done
|
||||
|
||||
t.SyncClient.MustSignalAndWait(ctx, stateDone, t.TestInstanceCount)
|
||||
t.SyncClient.MustSignalAndWait(context.Background(), stateDone, t.TestInstanceCount)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -116,7 +108,7 @@ func runBaselineClient(t *TestEnvironment) error {
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
addrs, err := collectMinersAddrs(t, ctx, t.IntParam("miners"))
|
||||
addrs, err := collectMinerAddrs(t, ctx, t.IntParam("miners"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -125,11 +117,13 @@ func runBaselineClient(t *TestEnvironment) error {
|
||||
|
||||
t.RecordMessage("got %v miner addrs", len(addrs))
|
||||
|
||||
if err := client.NetConnect(ctx, addrs[0].PeerAddr); err != nil {
|
||||
// select a random miner
|
||||
minerAddr := addrs[rand.Intn(len(addrs))]
|
||||
if err := client.NetConnect(ctx, minerAddr.PeerAddr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t.RecordMessage("client connected to miner")
|
||||
t.RecordMessage("selected %s as the miner", minerAddr.ActorAddr)
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
@ -144,19 +138,19 @@ func runBaselineClient(t *TestEnvironment) error {
|
||||
t.RecordMessage("file cid: %s", fcid)
|
||||
|
||||
// start deal
|
||||
deal := startDeal(ctx, addrs[0].ActorAddr, client, fcid)
|
||||
deal := startDeal(ctx, minerAddr.ActorAddr, client, fcid)
|
||||
t.RecordMessage("started deal: %s", deal)
|
||||
|
||||
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
t.RecordMessage("wait to be sealed")
|
||||
t.RecordMessage("waiting for deal to be sealed")
|
||||
waitDealSealed(t, ctx, client, deal)
|
||||
|
||||
carExport := true
|
||||
|
||||
t.RecordMessage("try to retrieve fcid")
|
||||
retrieve(t, ctx, err, client, fcid, carExport, data)
|
||||
t.RecordMessage("trying to retrieve %s", fcid)
|
||||
retrieveData(t, ctx, err, client, fcid, carExport, data)
|
||||
|
||||
t.SyncClient.MustSignalEntry(ctx, stateStopMining)
|
||||
|
||||
@ -167,40 +161,6 @@ func runBaselineClient(t *TestEnvironment) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func collectMinersAddrs(t *TestEnvironment, ctx context.Context, miners int) ([]MinerAddresses, error) {
|
||||
ch := make(chan MinerAddresses)
|
||||
sub := t.SyncClient.MustSubscribe(ctx, minersAddrsTopic, ch)
|
||||
|
||||
addrs := make([]MinerAddresses, 0, miners)
|
||||
for i := 0; i < miners; i++ {
|
||||
select {
|
||||
case a := <-ch:
|
||||
addrs = append(addrs, a)
|
||||
case err := <-sub.Done():
|
||||
return nil, fmt.Errorf("got error while waiting for miners addrs: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return addrs, nil
|
||||
}
|
||||
|
||||
func collectClientsAddrs(t *TestEnvironment, ctx context.Context, clients int) ([]peer.AddrInfo, error) {
|
||||
ch := make(chan peer.AddrInfo)
|
||||
sub := t.SyncClient.MustSubscribe(ctx, clientsAddrsTopic, ch)
|
||||
|
||||
addrs := make([]peer.AddrInfo, 0, clients)
|
||||
for i := 0; i < clients; i++ {
|
||||
select {
|
||||
case a := <-ch:
|
||||
addrs = append(addrs, a)
|
||||
case err := <-sub.Done():
|
||||
return nil, fmt.Errorf("got error while waiting for clients addrs: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return addrs, nil
|
||||
}
|
||||
|
||||
func startDeal(ctx context.Context, minerActorAddr address.Address, client *impl.FullNodeAPI, fcid cid.Cid) *cid.Cid {
|
||||
addr, err := client.WalletDefaultAddress(ctx)
|
||||
if err != nil {
|
||||
@ -243,7 +203,7 @@ loop:
|
||||
}
|
||||
}
|
||||
|
||||
func retrieve(t *TestEnvironment, ctx context.Context, err error, client *impl.FullNodeAPI, fcid cid.Cid, carExport bool, data []byte) {
|
||||
func retrieveData(t *TestEnvironment, ctx context.Context, err error, client *impl.FullNodeAPI, fcid cid.Cid, carExport bool, data []byte) {
|
||||
offers, err := client.ClientFindData(ctx, fcid)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -601,3 +601,37 @@ func waitForGenesis(t *TestEnvironment, ctx context.Context) (*GenesisMsg, error
|
||||
return nil, fmt.Errorf("error while waiting for genesis msg: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
func collectMinerAddrs(t *TestEnvironment, ctx context.Context, miners int) ([]MinerAddresses, error) {
|
||||
ch := make(chan MinerAddresses)
|
||||
sub := t.SyncClient.MustSubscribe(ctx, minersAddrsTopic, ch)
|
||||
|
||||
addrs := make([]MinerAddresses, 0, miners)
|
||||
for i := 0; i < miners; i++ {
|
||||
select {
|
||||
case a := <-ch:
|
||||
addrs = append(addrs, a)
|
||||
case err := <-sub.Done():
|
||||
return nil, fmt.Errorf("got error while waiting for miners addrs: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return addrs, nil
|
||||
}
|
||||
|
||||
func collectClientAddrs(t *TestEnvironment, ctx context.Context, clients int) ([]peer.AddrInfo, error) {
|
||||
ch := make(chan peer.AddrInfo)
|
||||
sub := t.SyncClient.MustSubscribe(ctx, clientsAddrsTopic, ch)
|
||||
|
||||
addrs := make([]peer.AddrInfo, 0, clients)
|
||||
for i := 0; i < clients; i++ {
|
||||
select {
|
||||
case a := <-ch:
|
||||
addrs = append(addrs, a)
|
||||
case err := <-sub.Done():
|
||||
return nil, fmt.Errorf("got error while waiting for clients addrs: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return addrs, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user