Skip to content

Commit

Permalink
fix: delete Exist method because it is not needed
Browse files Browse the repository at this point in the history
Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 committed Dec 5, 2023
1 parent 19ee272 commit f5afe4c
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 134 deletions.
2 changes: 1 addition & 1 deletion pkg/gateway/mirror/service/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Check warning on line 221 in pkg/gateway/mirror/service/discovery.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/discovery.go#L216-L221

Added lines #L216 - L221 were not covered by tests
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/gateway/mirror/service/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down
126 changes: 0 additions & 126 deletions pkg/gateway/mirror/service/mirror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5afe4c

Please sign in to comment.