Skip to content

Commit ed78681

Browse files
shiva-istariShivaji Kharse
andauthored
fix tests (#9694)
Co-authored-by: Shivaji Kharse <[email protected]>
1 parent 2da01c5 commit ed78681

3 files changed

Lines changed: 13 additions & 7 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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"sync"
2626
"time"
2727

28+
cerrdefs "github.com/containerd/errdefs"
2829
"github.com/docker/docker/api/types/container"
2930
"github.com/docker/docker/api/types/filters"
3031
"github.com/docker/docker/api/types/network"
@@ -335,7 +336,7 @@ func (c *LocalCluster) destroyContainers() error {
335336
wg.Add(1)
336337
go func(z *zero) {
337338
defer wg.Done()
338-
if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil {
339+
if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil && !cerrdefs.IsNotFound(err) {
339340
errChan <- errors.Wrapf(err, "error removing zero [%v]", z.cname())
340341
}
341342
}(zo)
@@ -345,7 +346,7 @@ func (c *LocalCluster) destroyContainers() error {
345346
wg.Add(1)
346347
go func(a *alpha) {
347348
defer wg.Done()
348-
if err := c.dcli.ContainerRemove(ctx, a.cid(), ro); err != nil {
349+
if err := c.dcli.ContainerRemove(ctx, a.cid(), ro); err != nil && !cerrdefs.IsNotFound(err) {
349350
errChan <- errors.Wrapf(err, "error removing alpha [%v]", a.cname())
350351
}
351352
}(aa)
@@ -645,7 +646,7 @@ func (c *LocalCluster) RecreateZero(id int) error {
645646
}
646647

647648
ro := container.RemoveOptions{RemoveVolumes: true, Force: true}
648-
if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil {
649+
if err := c.dcli.ContainerRemove(ctx, z.cid(), ro); err != nil && !cerrdefs.IsNotFound(err) {
649650
return errors.Wrapf(err, "error removing zero container [%v]", z.cname())
650651
}
651652

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/IBM/sarama v1.47.0
99
github.com/Masterminds/semver/v3 v3.4.0
1010
github.com/blevesearch/bleve/v2 v2.5.7
11+
github.com/containerd/errdefs v1.0.0
1112
github.com/dgraph-io/badger/v4 v4.9.1
1213
github.com/dgraph-io/dgo/v250 v250.0.0
1314
github.com/dgraph-io/gqlgen v0.13.2
@@ -88,7 +89,6 @@ require (
8889
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
8990
github.com/cespare/xxhash/v2 v2.3.0 // indirect
9091
github.com/chewxy/math32 v1.11.1 // indirect
91-
github.com/containerd/errdefs v1.0.0 // indirect
9292
github.com/containerd/errdefs/pkg v0.3.0 // indirect
9393
github.com/containerd/log v0.1.0 // indirect
9494
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect

0 commit comments

Comments
 (0)