ugly tests fix

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-02-18 23:58:40 +03:00
parent 8f4f500c5e
commit b3a435799b
2 changed files with 25 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ package gossip
import (
"context"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net"
@@ -27,6 +28,10 @@ import (
// type actionType int32
// type updateType int32
var (
ErrNotConnected = errors.New("register not connected")
)
const (
actionTypeInvalid int32 = iota
actionTypeCreate
@@ -100,6 +105,7 @@ type gossipRegister struct {
interval time.Duration
tcpInterval time.Duration
connected bool
connectRetry bool
connectTimeout time.Duration
sync.RWMutex
@@ -396,6 +402,7 @@ func (d *delegate) MergeRemoteState(buf []byte, join bool) {
}
func (g *gossipRegister) Connect(ctx context.Context) error {
g.connected = true
return nil
//return g.connect(g.opts.Addrs)
}
@@ -491,6 +498,7 @@ func (g *gossipRegister) subscribe() (chan *register.Result, chan bool) {
}
func (g *gossipRegister) Stop() error {
g.connected = false
select {
case <-g.done:
return nil
@@ -724,6 +732,9 @@ func (g *gossipRegister) Name() string {
}
func (g *gossipRegister) Register(ctx context.Context, s *register.Service, opts ...register.RegisterOption) error {
if !g.connected {
return ErrNotConnected
}
if g.opts.Logger.V(logger.DebugLevel) {
g.opts.Logger.Debugf(g.opts.Context, "[gossip] Register registering service: %s", s.Name)
}
@@ -776,6 +787,9 @@ func (g *gossipRegister) Register(ctx context.Context, s *register.Service, opts
}
func (g *gossipRegister) Deregister(ctx context.Context, s *register.Service, opts ...register.DeregisterOption) error {
if !g.connected {
return ErrNotConnected
}
if g.opts.Logger.V(logger.DebugLevel) {
g.opts.Logger.Debugf(g.opts.Context, "[gossip] Register deregistering service: %s", s.Name)