Skip to content

Commit

Permalink
chore: Allow creating new test network without init (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
kukugi authored Apr 15, 2021
1 parent 95eb4e7 commit 6c3cf97
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,33 @@ func New(t *testing.T, cfg Config) *Network {
return network
}

// New creates a new Network for integration tests without init.
func NewWithoutInit(t *testing.T, cfg Config, baseDir string, validators []*Validator) *Network {
// only one caller/test can create and use a network at a time
t.Log("acquiring test network lock")
lock.Lock()

network := &Network{
T: t,
BaseDir: baseDir,
Validators: validators,
Config: cfg,
}

t.Log("starting test network...")
for _, v := range network.Validators {
require.NoError(t, startInProcess(cfg, v))
}

t.Log("started test network")

// Ensure we cleanup incase any test was abruptly halted (e.g. SIGINT) as any
// defer in a test would not be called.
server.TrapSignal(network.Cleanup)

return network
}

// LatestHeight returns the latest height of the network or an error if the
// query fails or no validators exist.
func (n *Network) LatestHeight() (int64, error) {
Expand Down

0 comments on commit 6c3cf97

Please sign in to comment.