diff --git a/internal/test/e2e/host.go b/internal/test/e2e/host.go index e6867fa2c8..264d9e907d 100644 --- a/internal/test/e2e/host.go +++ b/internal/test/e2e/host.go @@ -107,9 +107,10 @@ type Host struct { dir string privKey types.PrivateKey - s *syncer.Syncer - cm *chain.Manager - chainDB *coreutils.BoltChainDB + s *syncer.Syncer + syncerCancel context.CancelFunc + cm *chain.Manager + chainDB *coreutils.BoltChainDB store *sqlite.Store wallet *wallet.SingleAddressWallet @@ -157,6 +158,7 @@ func (h *Host) Close() error { h.contracts.Close() h.storage.Close() h.store.Close() + h.syncerCancel() h.s.Close() h.chainDB.Close() return nil @@ -242,7 +244,8 @@ func NewHost(privKey types.PrivateKey, dir string, network *consensus.Network, g NetAddress: l.Addr().String(), }, syncer.WithPeerDiscoveryInterval(100*time.Millisecond), syncer.WithSyncInterval(100*time.Millisecond)) syncErrChan := make(chan error, 1) - go func() { syncErrChan <- s.Run(context.Background()) }() + syncerCtx, syncerCancel := context.WithCancel(context.Background()) + go func() { syncErrChan <- s.Run(syncerCtx) }() log := zap.NewNop() db, err := sqlite.OpenDatabase(filepath.Join(dir, "hostd.db"), log.Named("sqlite")) @@ -304,9 +307,10 @@ func NewHost(privKey types.PrivateKey, dir string, network *consensus.Network, g dir: dir, privKey: privKey, - s: s, - cm: cm, - chainDB: chainDB, + s: s, + syncerCancel: syncerCancel, + cm: cm, + chainDB: chainDB, store: db, wallet: wallet,