diff --git a/pkg/gateway/mirror/service/discovery.go b/pkg/gateway/mirror/service/discovery.go index 4538161053..57eed86a5b 100644 --- a/pkg/gateway/mirror/service/discovery.go +++ b/pkg/gateway/mirror/service/discovery.go @@ -216,7 +216,7 @@ func (d *discovery) startSync(ctx context.Context, prev map[string]target.Target for addr, name := range curAddrs { // When the status code of a regularly running Register RPC is Unimplemented, the connection to the target will be disconnected // so the status of the resource (CR) may be misaligned. To prevent this, change the status of the resource to Disconnected. - if !d.mirr.Exist(ctx, addr) && current[name].Phase == target.MirrorTargetPhaseConnected { + if !d.mirr.IsConnected(ctx, addr) && current[name].Phase == target.MirrorTargetPhaseConnected { err = errors.Join(err, d.updateMirrorTargetPhase(ctx, name, target.MirrorTargetPhaseDisconnected)) } } diff --git a/pkg/gateway/mirror/service/mirror.go b/pkg/gateway/mirror/service/mirror.go index d288dc6edc..786648f94a 100644 --- a/pkg/gateway/mirror/service/mirror.go +++ b/pkg/gateway/mirror/service/mirror.go @@ -41,7 +41,6 @@ type Mirror interface { Connect(ctx context.Context, targets ...*payload.Mirror_Target) error Disconnect(ctx context.Context, targets ...*payload.Mirror_Target) error IsConnected(ctx context.Context, addr string) bool - Exist(ctx context.Context, addr string) bool MirrorTargets() ([]*payload.Mirror_Target, error) RangeAllMirrorAddr(f func(addr string, _ any) bool) } @@ -306,12 +305,6 @@ func (m *mirr) IsConnected(ctx context.Context, addr string) bool { return m.gateway.GRPCClient().IsConnected(ctx, addr) } -// Exist checks if the given address exists in the Mmirror. -func (m *mirr) Exist(_ context.Context, addr string) bool { - _, ok := m.addrl.Load(addr) - return ok -} - // MirrorTargets returns the Mirror targets, including the address of this gateway and the addresses of other Mirror Gateways // to which this gateway is currently connected. func (m *mirr) MirrorTargets() ([]*payload.Mirror_Target, error) { diff --git a/pkg/gateway/mirror/service/mirror_test.go b/pkg/gateway/mirror/service/mirror_test.go index 16b0604d0a..a88f9c3794 100644 --- a/pkg/gateway/mirror/service/mirror_test.go +++ b/pkg/gateway/mirror/service/mirror_test.go @@ -962,132 +962,6 @@ func Test_mirr_connectedOtherMirrorAddrs(t *testing.T) { // } // } // -// func Test_mirr_Exist(t *testing.T) { -// type args struct { -// in0 context.Context -// addr string -// } -// type fields struct { -// addrl sync.Map[string, any] -// selfMirrTgts []*payload.Mirror_Target -// selfMirrAddrl sync.Map[string, any] -// gwAddrl sync.Map[string, any] -// eg errgroup.Group -// registerDur time.Duration -// gateway Gateway -// } -// type want struct { -// want bool -// } -// type test struct { -// name string -// args args -// fields fields -// want want -// checkFunc func(want, bool) error -// beforeFunc func(*testing.T, args) -// afterFunc func(*testing.T, args) -// } -// defaultCheckFunc := func(w want, got bool) error { -// if !reflect.DeepEqual(got, w.want) { -// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) -// } -// return nil -// } -// tests := []test{ -// // TODO test cases -// /* -// { -// name: "test_case_1", -// args: args { -// in0:nil, -// addr:"", -// }, -// fields: fields { -// addrl:nil, -// selfMirrTgts:nil, -// selfMirrAddrl:nil, -// gwAddrl:nil, -// eg:nil, -// registerDur:nil, -// gateway:nil, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// }, -// */ -// -// // TODO test cases -// /* -// func() test { -// return test { -// name: "test_case_2", -// args: args { -// in0:nil, -// addr:"", -// }, -// fields: fields { -// addrl:nil, -// selfMirrTgts:nil, -// selfMirrAddrl:nil, -// gwAddrl:nil, -// eg:nil, -// registerDur:nil, -// gateway:nil, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// } -// }(), -// */ -// } -// -// for _, tc := range tests { -// test := tc -// t.Run(test.name, func(tt *testing.T) { -// tt.Parallel() -// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) -// if test.beforeFunc != nil { -// test.beforeFunc(tt, test.args) -// } -// if test.afterFunc != nil { -// defer test.afterFunc(tt, test.args) -// } -// checkFunc := test.checkFunc -// if test.checkFunc == nil { -// checkFunc = defaultCheckFunc -// } -// m := &mirr{ -// addrl: test.fields.addrl, -// selfMirrTgts: test.fields.selfMirrTgts, -// selfMirrAddrl: test.fields.selfMirrAddrl, -// gwAddrl: test.fields.gwAddrl, -// eg: test.fields.eg, -// registerDur: test.fields.registerDur, -// gateway: test.fields.gateway, -// } -// -// got := m.Exist(test.args.in0, test.args.addr) -// if err := checkFunc(test.want, got); err != nil { -// tt.Errorf("error = %v", err) -// } -// -// }) -// } -// } -// // func Test_mirr_RangeAllMirrorAddr(t *testing.T) { // type args struct { // f func(addr string, _ any) bool