Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
Signed-off-by: NikitaSkrynnik <[email protected]>
  • Loading branch information
NikitaSkrynnik committed Nov 12, 2024
1 parent 372da31 commit da53f35
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pkg/networkservice/chains/client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func WithoutRefresh() Option {
}
}

// WithoutReselectFunc sets a function for changing request parameters on reselect
func WithoutReselectFunc(f func(*networkservice.NetworkServiceRequest)) Option {
// WithReselectFunc sets a function for changing request parameters on reselect
func WithReselectFunc(f func(*networkservice.NetworkServiceRequest)) Option {
return func(c *clientOptions) {
c.reselectFunc = f
}
Expand Down
19 changes: 8 additions & 11 deletions pkg/networkservice/chains/nsmgr/heal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,35 +923,32 @@ func TestNSMGRHealEndpoint_CustomReselectFunc(t *testing.T) {
SetRegistryProxySupplier(nil).
Build()

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)
nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService(t.Name()))
nsReg, err := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken).Register(ctx, defaultRegistryService(t.Name()))
require.NoError(t, err)

nseReg := defaultRegistryEndpoint(nsReg.Name)
nse := domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken)

request := defaultRequest(nsReg.Name)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nsclient.WithHealClient(heal.NewClient(ctx)),
nsclient.WithoutReselectFunc(
nsclient.WithReselectFunc(
func(request *networkservice.NetworkServiceRequest) {
request.Connection.Labels = make(map[string]string)
request.Connection.Labels["key"] = "value"
request.Connection.NetworkServiceEndpointName = ""
}))

request := defaultRequest(nsReg.Name)
_, err = nsc.Request(ctx, request.Clone())
require.NoError(t, err)

nse.Cancel()

checker := checkrequest.NewServer(t, func(t *testing.T, nsr *networkservice.NetworkServiceRequest) {
require.Contains(t, nsr.Connection.Labels, "key")
})
counter := new(count.Server)
nseReg2 := defaultRegistryEndpoint(nsReg.Name)
nseReg2.Name += "-2"
domain.Nodes[0].NewEndpoint(ctx, nseReg2, sandbox.GenerateTestToken, counter, checker)
domain.Nodes[0].NewEndpoint(ctx, nseReg2, sandbox.GenerateTestToken)

require.Eventually(t, func() bool { return counter.UniqueRequests() > 0 }, timeout, tick)
require.Eventually(t, func() bool {
resp, err := nsc.Request(ctx, request.Clone())
return err == nil && resp.Labels["key"] == "value"
}, timeout, tick)
}
12 changes: 6 additions & 6 deletions pkg/networkservice/common/begin/event_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ type ReselectFunc func(request *networkservice.NetworkServiceRequest)

// DefaultReselectFunc - default ReselectFunc
var DefaultReselectFunc ReselectFunc = func(request *networkservice.NetworkServiceRequest) {
request.GetConnection().Mechanism = nil
request.GetConnection().NetworkServiceEndpointName = ""
request.GetConnection().State = networkservice.State_RESELECT_REQUESTED
if request.GetConnection() != nil {
request.GetConnection().Mechanism = nil
request.GetConnection().NetworkServiceEndpointName = ""
request.GetConnection().State = networkservice.State_RESELECT_REQUESTED
}
}

// EventFactory - allows firing off a Request or Close event from midchain
Expand Down Expand Up @@ -115,9 +117,7 @@ func (f *eventFactoryClient) Request(opts ...Option) <-chan error {
if o.reselect {
ctx, cancel := f.ctxFunc()
_, _ = f.client.Close(ctx, request.GetConnection(), f.opts...)
if request.GetConnection() != nil {
f.reselectFunc(request)
}
f.reselectFunc(request)
cancel()
}
ctx, cancel := f.ctxFunc()
Expand Down

0 comments on commit da53f35

Please sign in to comment.