From 82b15d2637655508bc92141db0b739a012ff362c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 8 Oct 2020 15:59:06 -0700 Subject: [PATCH] cleanup tests on finish --- chain/sync_test.go | 8 ++++---- node/test/builder.go | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/chain/sync_test.go b/chain/sync_test.go index 1b06f604b..318f6d82f 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -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), @@ -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 { @@ -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)), @@ -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 diff --git a/node/test/builder.go b/node/test/builder.go index a3455f376..d9ec04460 100644 --- a/node/test/builder.go +++ b/node/test/builder.go @@ -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), @@ -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) @@ -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) @@ -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)), @@ -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 { @@ -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)), @@ -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 {