-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chain: test sequential start and stop of client
adds a unit test that verifies that the neutrino client can start and stop sequentially without errors or races in a finite amount of time. adjusts the Start method of the client to remove a data race on the quit channel.
- Loading branch information
Showing
2 changed files
with
38 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,39 @@ | ||
package chain | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestNeutrinoClientMultipleRestart ensures that multiple goroutines | ||
// can Start and Stop the client without errors or races. | ||
func TestNeutrinoClientMultipleRestart(t *testing.T) { | ||
// call notifyreceived and rescan in a loop | ||
// TestNeutrinoClientStartStop ensures that the client | ||
// can sequentially Start and Stop without errors or races. | ||
func TestNeutrinoClientStartStop(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) | ||
t.Cleanup(cancel) | ||
nc := newMockNeutrinoClient(t) | ||
_ = nc | ||
numRestarts := 5 | ||
|
||
startStop := func() <-chan struct{} { | ||
done := make(chan struct{}) | ||
go func() { | ||
defer close(done) | ||
err := nc.Start() | ||
require.NoError(t, err) | ||
nc.Stop() | ||
nc.WaitForShutdown() | ||
}() | ||
return done | ||
} | ||
|
||
for i := 0; i < numRestarts; i++ { | ||
done := startStop() | ||
select { | ||
case <-ctx.Done(): | ||
t.Fatal("timed out") | ||
case <-done: | ||
} | ||
} | ||
} |