Skip to content

Commit

Permalink
Merge pull request #4256 from filecoin-project/steb/call-stop
Browse files Browse the repository at this point in the history
cleanup tests on finish
  • Loading branch information
magik6k authored Oct 9, 2020
2 parents e1792ff + 82b15d2 commit bacac24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions chain/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ func (tu *syncTestUtil) addSourceNode(gen int) {
sourceRepo, genesis, blocks := tu.repoWithChain(tu.t, gen)
var out api.FullNode

// TODO: Don't ignore stop
_, err := node.New(tu.ctx,
stop, err := node.New(tu.ctx,
node.FullAPI(&out),
node.Online(),
node.Repo(sourceRepo),
Expand All @@ -232,6 +231,7 @@ func (tu *syncTestUtil) addSourceNode(gen int) {
node.Override(new(modules.Genesis), modules.LoadGenesis(genesis)),
)
require.NoError(tu.t, err)
tu.t.Cleanup(func() { _ = stop(context.Background()) })

lastTs := blocks[len(blocks)-1].Blocks
for _, lastB := range lastTs {
Expand All @@ -253,8 +253,7 @@ func (tu *syncTestUtil) addClientNode() int {

var out api.FullNode

// TODO: Don't ignore stop
_, err := node.New(tu.ctx,
stop, err := node.New(tu.ctx,
node.FullAPI(&out),
node.Online(),
node.Repo(repo.NewMemory(nil)),
Expand All @@ -264,6 +263,7 @@ func (tu *syncTestUtil) addClientNode() int {
node.Override(new(modules.Genesis), modules.LoadGenesis(tu.genesis)),
)
require.NoError(tu.t, err)
tu.t.Cleanup(func() { _ = stop(context.Background()) })

tu.nds = append(tu.nds, out)
return len(tu.nds) - 1
Expand Down
17 changes: 9 additions & 8 deletions node/test/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ func CreateTestStorageNode(ctx context.Context, t *testing.T, waddr address.Addr
var minerapi api.StorageMiner

mineBlock := make(chan miner2.MineReq)
// TODO: use stop
_, err = node.New(ctx,
stop, err := node.New(ctx,
node.StorageMiner(&minerapi),
node.Online(),
node.Repo(r),
Expand All @@ -118,6 +117,7 @@ func CreateTestStorageNode(ctx context.Context, t *testing.T, waddr address.Addr
if err != nil {
t.Fatalf("failed to construct node: %v", err)
}
t.Cleanup(func() { _ = stop(context.Background()) })

/*// Bootstrap with full node
remoteAddrs, err := tnd.NetAddrsListen(ctx)
Expand All @@ -138,7 +138,9 @@ func CreateTestStorageNode(ctx context.Context, t *testing.T, waddr address.Addr
}

func Builder(t *testing.T, nFull int, storage []test.StorageMiner, opts ...node.Option) ([]test.TestNode, []test.TestStorageNode) {
ctx := context.Background()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

mn := mocknet.New(ctx)

fulls := make([]test.TestNode, nFull)
Expand Down Expand Up @@ -214,9 +216,7 @@ func Builder(t *testing.T, nFull int, storage []test.StorageMiner, opts ...node.
genesis = node.Override(new(modules.Genesis), modules.LoadGenesis(genbuf.Bytes()))
}

var err error
// TODO: Don't ignore stop
_, err = node.New(ctx,
stop, err := node.New(ctx,
node.FullAPI(&fulls[i].FullNode),
node.Online(),
node.Repo(repo.NewMemory(nil)),
Expand All @@ -229,7 +229,7 @@ func Builder(t *testing.T, nFull int, storage []test.StorageMiner, opts ...node.
if err != nil {
t.Fatal(err)
}

t.Cleanup(func() { _ = stop(context.Background()) })
}

for i, def := range storage {
Expand Down Expand Up @@ -364,7 +364,7 @@ func MockSbBuilder(t *testing.T, nFull int, storage []test.StorageMiner, options

var err error
// TODO: Don't ignore stop
_, err = node.New(ctx,
stop, err := node.New(ctx,
node.FullAPI(&fulls[i].FullNode),
node.Online(),
node.Repo(repo.NewMemory(nil)),
Expand All @@ -379,6 +379,7 @@ func MockSbBuilder(t *testing.T, nFull int, storage []test.StorageMiner, options
if err != nil {
t.Fatalf("%+v", err)
}
t.Cleanup(func() { _ = stop(context.Background()) })
}

for i, def := range storage {
Expand Down

0 comments on commit bacac24

Please sign in to comment.