If rendezvous wasn't start or was already stopped ignore Stop call (#1340)

This commit is contained in:
Dmitry Shulyak 2019-01-09 09:40:07 +02:00 committed by GitHub
parent 944a35a11b
commit 54022561f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -92,6 +92,9 @@ func (r *Rendezvous) Start() error {
func (r *Rendezvous) Stop() error {
r.mu.Lock()
defer r.mu.Unlock()
if r.client == nil {
return nil
}
r.cancelRootCtx()
if err := r.client.Close(); err != nil {
return err

View File

@ -83,6 +83,12 @@ func TestRendezvousRegisterAndDiscoverExitGracefully(t *testing.T) {
require.EqualError(t, errDiscoveryIsStopped, err.Error())
}
func TestStopStoppedNode(t *testing.T) {
r, err := NewRendezvous(make([]ma.Multiaddr, 1), nil, nil)
require.NoError(t, err)
require.NoError(t, r.Stop())
}
func BenchmarkRendezvousStart(b *testing.B) {
identity, err := crypto.GenerateKey()
require.NoError(b, err)