Skip to content

Commit 7ff8aa3

Browse files
Shivaji KharseShivaji Kharse
authored andcommitted
fix tests
1 parent 2da01c5 commit 7ff8aa3

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

conn/node.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"go.etcd.io/etcd/raft/v3/raftpb"
2424
"go.opentelemetry.io/otel"
2525
"go.opentelemetry.io/otel/trace"
26+
27+
"google.golang.org/grpc/connectivity"
2628
"google.golang.org/protobuf/proto"
2729

2830
"github.com/dgraph-io/badger/v4/y"
@@ -760,10 +762,13 @@ func (n *Node) joinCluster(ctx context.Context, rc *pb.RaftContext) (*api.Payloa
760762
return nil, errors.Errorf("REUSE_RAFTID: Raft ID duplicates mine: %+v", rc)
761763
}
762764

763-
// Check that the new node is not already part of the group.
765+
// Reject if a peer with the same Raft ID is already registered at a
766+
// different address AND that peer is still genuinely connected. Using the
767+
// gRPC connection state is more accurate than IsHealthy(), which relies on
768+
// a heartbeat timestamp and stays "healthy" for ~2s after the peer drops.
764769
if addr, ok := n.Peer(rc.Id); ok && rc.Addr != addr {
765-
// There exists a healthy connection to server with same id.
766-
if _, err := GetPools().Get(addr); err == nil {
770+
if pool, err := GetPools().Get(addr); err == nil &&
771+
pool.Get().GetState() == connectivity.Ready {
767772
return &api.Payload{}, errors.Errorf(
768773
"REUSE_ADDR: IP Address same as existing peer: %s", addr)
769774
}

dgraphtest/local_cluster.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func (c *LocalCluster) destroyContainers() error {
335335
wg.Add(1)
336336
go func(z *zero) {
337337
defer wg.Done()
338-
if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil {
338+
if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil && !docker.IsErrNotFound(err) {
339339
errChan <- errors.Wrapf(err, "error removing zero [%v]", z.cname())
340340
}
341341
}(zo)
@@ -345,7 +345,7 @@ func (c *LocalCluster) destroyContainers() error {
345345
wg.Add(1)
346346
go func(a *alpha) {
347347
defer wg.Done()
348-
if err := c.dcli.ContainerRemove(ctx, a.cid(), ro); err != nil {
348+
if err := c.dcli.ContainerRemove(ctx, a.cid(), ro); err != nil && !docker.IsErrNotFound(err) {
349349
errChan <- errors.Wrapf(err, "error removing alpha [%v]", a.cname())
350350
}
351351
}(aa)
@@ -645,7 +645,7 @@ func (c *LocalCluster) RecreateZero(id int) error {
645645
}
646646

647647
ro := container.RemoveOptions{RemoveVolumes: true, Force: true}
648-
if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil {
648+
if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil && !docker.IsErrNotFound(err) {
649649
return errors.Wrapf(err, "error removing zero container [%v]", z.cname())
650650
}
651651

0 commit comments

Comments
 (0)