Skip to content

Commit

Permalink
[test] add main additional functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
  • Loading branch information
glazychev-art committed Oct 28, 2021
1 parent 9501d5b commit 9c2180e
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Build
run: go build -race ./...
- name: Test
run: go test -race -count 50 -run "TestNSMGR_HealNSMgr" -timeout 1h ./...
run: go test -race -count 50 -run "TestNSMGR_.*" -timeout 1h ./...
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
Expand Down
33 changes: 19 additions & 14 deletions pkg/networkservice/chains/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package client

import (
"context"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/dial"

"github.com/google/uuid"
"github.com/networkservicemesh/api/pkg/api/networkservice"
Expand All @@ -29,7 +30,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/clientconn"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/clienturl"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/connect"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/dial"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/null"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/refresh"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/setlogoption"
Expand All @@ -53,19 +53,24 @@ func NewClient(ctx context.Context, clientOpts ...Option) networkservice.Network

return chain.NewNetworkServiceClient(
append(
[]networkservice.NetworkServiceClient{
adapters.NewServerToClient(setlogoption.NewServer(map[string]string{"name": opts.name})),
updatepath.NewClient(opts.name),
begin.NewClient(),
metadata.NewClient(),
opts.refreshClient,
clienturl.NewClient(opts.clientURL),
clientconn.NewClient(opts.cc),
dial.NewClient(ctx,
dial.WithDialOptions(opts.dialOptions...),
dial.WithDialTimeout(opts.dialTimeout),
),
},
append(
[]networkservice.NetworkServiceClient{
adapters.NewServerToClient(setlogoption.NewServer(map[string]string{"name": opts.name})),
updatepath.NewClient(opts.name),
begin.NewClient(),
metadata.NewClient(),
opts.refreshClient,
clienturl.NewClient(opts.clientURL),
clientconn.NewClient(opts.cc),
},
append(
opts.mainAdditionalFunctionality,
dial.NewClient(ctx,
dial.WithDialOptions(opts.dialOptions...),
dial.WithDialTimeout(opts.dialTimeout),
),
)...,
),
append(
opts.additionalFunctionality,
opts.authorizeClient,
Expand Down
9 changes: 9 additions & 0 deletions pkg/networkservice/chains/client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type clientOptions struct {
refreshClient networkservice.NetworkServiceClient
dialOptions []grpc.DialOption
dialTimeout time.Duration

mainAdditionalFunctionality []networkservice.NetworkServiceClient
}

// Option modifies default client chain values.
Expand Down Expand Up @@ -68,6 +70,13 @@ func WithAdditionalFunctionality(additionalFunctionality ...networkservice.Netwo
})
}

// WithMainAdditionalFunctionality sets additionalFunctionality for the client. Note: this adds into tail of the client chain.
func WithMainAdditionalFunctionality(mainAdditionalFunctionality ...networkservice.NetworkServiceClient) Option {
return Option(func(c *clientOptions) {
c.mainAdditionalFunctionality = mainAdditionalFunctionality
})
}

// WithAuthorizeClient sets authorizeClient for the client chain.
func WithAuthorizeClient(authorizeClient networkservice.NetworkServiceClient) Option {
if authorizeClient == nil {
Expand Down
14 changes: 8 additions & 6 deletions pkg/networkservice/chains/nsmgr/heal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"testing"
"time"

"github.com/networkservicemesh/api/pkg/api/networkservice"

"github.com/stretchr/testify/require"
"go.uber.org/goleak"

Expand Down Expand Up @@ -87,7 +89,7 @@ func testNSMGRHealEndpoint(t *testing.T, nodeNum int) {

request := defaultRequest(nsReg.Name)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, heal.NewClient(ctx))
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, []networkservice.NetworkServiceClient {heal.NewClient(ctx)})

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand Down Expand Up @@ -162,7 +164,7 @@ func testNSMGRHealForwarder(t *testing.T, nodeNum int) {

request := defaultRequest(nsReg.Name)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, heal.NewClient(ctx))
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, []networkservice.NetworkServiceClient {heal.NewClient(ctx)})

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand Down Expand Up @@ -245,7 +247,7 @@ func testNSMGRHealNSMgr(t *testing.T, nodeNum int, restored bool) {

request := defaultRequest(nsReg.Name)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, heal.NewClient(ctx))
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, []networkservice.NetworkServiceClient {heal.NewClient(ctx)})

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand Down Expand Up @@ -315,7 +317,7 @@ func TestNSMGR_HealRegistry(t *testing.T) {

request := defaultRequest(nsReg.Name)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, heal.NewClient(ctx))
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, []networkservice.NetworkServiceClient {heal.NewClient(ctx)})

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand All @@ -329,7 +331,7 @@ func TestNSMGR_HealRegistry(t *testing.T) {
require.NoError(t, err)

// 3. Check new client request
nsc = domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, heal.NewClient(ctx))
nsc = domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, []networkservice.NetworkServiceClient {heal.NewClient(ctx)})

_, err = nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand Down Expand Up @@ -389,7 +391,7 @@ func testNSMGRCloseHeal(t *testing.T, withNSEExpiration bool) {

nscCtx, nscCtxCancel := context.WithCancel(ctx)

nsc := domain.Nodes[0].NewClient(nscCtx, sandbox.GenerateTestToken, heal.NewClient(ctx))
nsc := domain.Nodes[0].NewClient(nscCtx, sandbox.GenerateTestToken, []networkservice.NetworkServiceClient {heal.NewClient(ctx)})

reqCtx, reqCancel := context.WithTimeout(ctx, time.Second)
defer reqCancel()
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkservice/chains/nsmgr/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestCreateEndpointDuringRequest(t *testing.T) {

domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, makerServer)

nsc := domain.Nodes[1].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[1].NewClient(ctx, sandbox.GenerateTestToken, nil)

// check first request
conn, err := nsc.Request(ctx, &networkservice.NetworkServiceRequest{
Expand Down
6 changes: 3 additions & 3 deletions pkg/networkservice/chains/nsmgr/single_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Test_DNSUsecase(t *testing.T) {

const expectedCorefile = ". {\n\tlog\n\treload\n}\nmy.domain1 {\n\tfanout . 8.8.4.4 8.8.8.8\n\tcache\n\tlog\n}\n"

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, dnscontext.NewClient(
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil, dnscontext.NewClient(
dnscontext.WithChainContext(ctx),
dnscontext.WithCorefilePath(corefilePath),
dnscontext.WithResolveConfigPath(resolveConfigPath),
Expand Down Expand Up @@ -175,7 +175,7 @@ func Test_ShouldCorrectlyAddEndpointsWithSameNames(t *testing.T) {
<-time.After(sandbox.RegistryExpiryDuration)

// 3. Request
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

for _, nseReg := range nseRegs {
_, err := nsc.Request(ctx, defaultRequest(nseReg.NetworkServiceNames[0]))
Expand Down Expand Up @@ -237,7 +237,7 @@ func Test_ShouldParseNetworkServiceLabelsTemplate(t *testing.T) {

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

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)
require.NoError(t, err)

req := defaultRequest(nsReg.Name)
Expand Down
20 changes: 10 additions & 10 deletions pkg/networkservice/chains/nsmgr/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (s *nsmgrSuite) Test_Remote_ParallelUsecase() {
time.Sleep(time.Millisecond * 100)
nse = s.domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)
}()
nsc := s.domain.Nodes[1].NewClient(ctx, sandbox.GenerateTestToken)
nsc := s.domain.Nodes[1].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := defaultRequest(nsReg.Name)

Expand Down Expand Up @@ -175,7 +175,7 @@ func (s *nsmgrSuite) Test_SelectsRestartingEndpointUsecase() {
})

// 3. Create client and request endpoint
nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

conn, err := nsc.Request(ctx, defaultRequest(nsReg.Name))
require.NoError(t, err)
Expand Down Expand Up @@ -230,7 +230,7 @@ func (s *nsmgrSuite) Test_Remote_BusyEndpointsUsecase() {

nses[3] = s.domain.Nodes[1].NewEndpoint(ctx, nseRegs[3], sandbox.GenerateTestToken, counter)
}()
nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := defaultRequest(nsReg.Name)

Expand Down Expand Up @@ -277,7 +277,7 @@ func (s *nsmgrSuite) Test_RemoteUsecase() {

nse := s.domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)

nsc := s.domain.Nodes[1].NewClient(ctx, sandbox.GenerateTestToken)
nsc := s.domain.Nodes[1].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := defaultRequest(nsReg.Name)

Expand Down Expand Up @@ -321,7 +321,7 @@ func (s *nsmgrSuite) Test_ConnectToDeadNSEUsecase() {

nse := s.domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)

nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := defaultRequest(nsReg.Name)

Expand Down Expand Up @@ -370,7 +370,7 @@ func (s *nsmgrSuite) Test_LocalUsecase() {

nse := s.domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)

nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := defaultRequest(nsReg.Name)

Expand Down Expand Up @@ -428,7 +428,7 @@ func (s *nsmgrSuite) Test_PassThroughRemoteUsecase() {
)
}

nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := defaultRequest(nsReg.Name)

Expand Down Expand Up @@ -492,7 +492,7 @@ func (s *nsmgrSuite) Test_PassThroughLocalUsecase() {
)
}

nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := defaultRequest(nsReg.Name)

Expand Down Expand Up @@ -570,7 +570,7 @@ func (s *nsmgrSuite) Test_PassThroughSameSourceSelector() {
)
}

nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := defaultRequest(nsReg.Name)

Expand Down Expand Up @@ -642,7 +642,7 @@ func (s *nsmgrSuite) Test_PassThroughLocalUsecaseMultiLabel() {
labelBvalue = ""
}

nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := defaultRequest(nsReg.Name)

Expand Down
4 changes: 2 additions & 2 deletions pkg/networkservice/chains/nsmgr/unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Test_Local_NoURLUsecase(t *testing.T) {

domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand Down Expand Up @@ -119,7 +119,7 @@ func Test_MultiForwarderSendfd(t *testing.T) {

domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, kernel.NewClient(), sendfd.NewClient())
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil, kernel.NewClient(), sendfd.NewClient())

request := defaultRequest(nsReg.Name)

Expand Down
2 changes: 1 addition & 1 deletion pkg/networkservice/chains/nsmgr/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func testNSEAndClient(

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

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := defaultRequest(nseReg.NetworkServiceNames[0])

Expand Down
12 changes: 6 additions & 6 deletions pkg/networkservice/chains/nsmgrproxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestNSMGR_InterdomainUseCase(t *testing.T) {

cluster2.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken)

nsc := cluster1.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := cluster1.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestNSMGR_Interdomain_TwoNodesNSEs(t *testing.T) {
}
cluster2.Nodes[0].NewEndpoint(ctx, nseReg2, sandbox.GenerateTestToken)

nsc := cluster1.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := cluster1.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestNSMGR_FloatingInterdomainUseCase(t *testing.T) {

cluster2.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken)

nsc := cluster1.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := cluster1.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down Expand Up @@ -349,7 +349,7 @@ func TestNSMGR_FloatingInterdomainUseCase_FloatingNetworkServiceNameRegistration

cluster2.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken)

nsc := cluster1.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := cluster1.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down Expand Up @@ -462,7 +462,7 @@ func TestNSMGR_FloatingInterdomain_FourClusters(t *testing.T) {

// connect to first endpoint from cluster2

nsc := cluster1.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := cluster1.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down Expand Up @@ -602,7 +602,7 @@ func Test_Interdomain_PassThroughUsecase(t *testing.T) {
clusters[i].Nodes[0].NewEndpoint(ctx, nsesReg, sandbox.GenerateTestToken, additionalFunctionality...)
}

nsc := clusters[clusterCount-1].Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)
nsc := clusters[clusterCount-1].Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, nil)

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkservice/common/refresh/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func TestRefreshClient_Sandbox(t *testing.T) {
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, refreshSrv)

nscTokenGenerator := sandbox.GenerateExpiringToken(sandboxExpireTimeout)
nsc := domain.Nodes[1].NewClient(ctx, nscTokenGenerator)
nsc := domain.Nodes[1].NewClient(ctx, nscTokenGenerator, nil)

refreshSrv.beforeRequest("test-conn")
_, err = nsc.Request(ctx, mkRequest("test-conn", nil))
Expand Down
2 changes: 2 additions & 0 deletions pkg/tools/sandbox/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,15 @@ func (n *Node) registerEndpoint(
func (n *Node) NewClient(
ctx context.Context,
generatorFunc token.GeneratorFunc,
mainAdditionalFunctionality []networkservice.NetworkServiceClient,
additionalFunctionality ...networkservice.NetworkServiceClient,
) networkservice.NetworkServiceClient {
return client.NewClient(
ctx,
client.WithClientURL(CloneURL(n.NSMgr.URL)),
client.WithDialOptions(DialOptions(WithTokenGenerator(generatorFunc))...),
client.WithAuthorizeClient(authorize.NewClient(authorize.Any())),
client.WithMainAdditionalFunctionality(mainAdditionalFunctionality...),
client.WithAdditionalFunctionality(additionalFunctionality...),
client.WithDialTimeout(DialTimeout),
)
Expand Down

0 comments on commit 9c2180e

Please sign in to comment.