Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sdk#740] Rework sandbox to use tokenTimeout instead of tokenGenerator #996

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions pkg/networkservice/chains/nsmgr/heal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func testNSMGRHealEndpoint(t *testing.T, nodeNum int) {
SetRegistryProxySupplier(nil).
Build()

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.DefaultTokenTimeout)

nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService())
require.NoError(t, err)
Expand All @@ -81,11 +81,11 @@ func testNSMGRHealEndpoint(t *testing.T, nodeNum int) {
nseCtx, nseCtxCancel := context.WithCancel(context.Background())

counter := &counterServer{}
domain.Nodes[nodeNum].NewEndpoint(nseCtx, nseReg, sandbox.GenerateTestToken, counter)
domain.Nodes[nodeNum].NewEndpoint(nseCtx, nseReg, sandbox.DefaultTokenTimeout, counter)

request := defaultRequest(nsReg.Name)

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

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand All @@ -95,7 +95,7 @@ func testNSMGRHealEndpoint(t *testing.T, nodeNum int) {

nseReg2 := defaultRegistryEndpoint(nsReg.Name)
nseReg2.Name += "-2"
domain.Nodes[nodeNum].NewEndpoint(ctx, nseReg2, sandbox.GenerateTestToken, counter)
domain.Nodes[nodeNum].NewEndpoint(ctx, nseReg2, sandbox.DefaultTokenTimeout, counter)

// Wait reconnecting to the new NSE
require.Eventually(t, checkSecondRequestsReceived(counter.UniqueRequests), timeout, tick)
Expand Down Expand Up @@ -150,24 +150,24 @@ func testNSMGRHealForwarder(t *testing.T, nodeNum int) {
SetRegistryProxySupplier(nil).
SetNodeSetup(func(ctx context.Context, node *sandbox.Node, nodeN int) {
if nodeN != nodeNum {
sandbox.SetupDefaultNode(ctx, node, nsmgr.NewServer)
sandbox.SetupDefaultNode(ctx, node, sandbox.DefaultTokenTimeout, nsmgr.NewServer)
} else {
forwarderCtxCancel = setupCancelableForwarderNode(ctx, node)
}
}).
Build()

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.DefaultTokenTimeout)

nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService())
require.NoError(t, err)

counter := &counterServer{}
domain.Nodes[1].NewEndpoint(ctx, defaultRegistryEndpoint(nsReg.Name), sandbox.GenerateTestToken, counter)
domain.Nodes[1].NewEndpoint(ctx, defaultRegistryEndpoint(nsReg.Name), sandbox.DefaultTokenTimeout, counter)

request := defaultRequest(nsReg.Name)

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

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand All @@ -178,7 +178,7 @@ func testNSMGRHealForwarder(t *testing.T, nodeNum int) {
forwarderReg := &registry.NetworkServiceEndpoint{
Name: sandbox.UniqueName("forwarder-2"),
}
domain.Nodes[nodeNum].NewForwarder(ctx, forwarderReg, sandbox.GenerateTestToken)
domain.Nodes[nodeNum].NewForwarder(ctx, forwarderReg, sandbox.DefaultTokenTimeout)

// Wait reconnecting through the new Forwarder
require.Eventually(t, checkSecondRequestsReceived(counter.UniqueRequests), timeout, tick)
Expand All @@ -198,12 +198,12 @@ func testNSMGRHealForwarder(t *testing.T, nodeNum int) {
}

func setupCancelableForwarderNode(ctx context.Context, node *sandbox.Node) context.CancelFunc {
node.NewNSMgr(ctx, sandbox.UniqueName("nsmgr"), nil, sandbox.GenerateTestToken, nsmgr.NewServer)
node.NewNSMgr(ctx, sandbox.UniqueName("nsmgr"), nil, sandbox.DefaultTokenTimeout, nsmgr.NewServer)

forwarderCtx, forwarderCtxCancel := context.WithCancel(ctx)
node.NewForwarder(forwarderCtx, &registry.NetworkServiceEndpoint{
Name: sandbox.UniqueName("forwarder"),
}, sandbox.GenerateTestToken)
}, sandbox.DefaultTokenTimeout)

return forwarderCtxCancel
}
Expand Down Expand Up @@ -246,26 +246,26 @@ func testNSMGRHealNSMgr(t *testing.T, nodeNum int, restored bool) {
SetRegistryProxySupplier(nil).
SetNodeSetup(func(ctx context.Context, node *sandbox.Node, nodeN int) {
if nodeN != nodeNum {
sandbox.SetupDefaultNode(ctx, node, nsmgr.NewServer)
sandbox.SetupDefaultNode(ctx, node, sandbox.DefaultTokenTimeout, nsmgr.NewServer)
} else {
nsmgrCtxCancel = setupCancellableNSMgrNode(ctx, node)
}
}).
Build()

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.DefaultTokenTimeout)

nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService())
require.NoError(t, err)

nseReg := defaultRegistryEndpoint(nsReg.Name)

counter := &counterServer{}
domain.Nodes[1].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)
domain.Nodes[1].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, counter)

request := defaultRequest(nsReg.Name)

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

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
Expand All @@ -274,7 +274,7 @@ func testNSMGRHealNSMgr(t *testing.T, nodeNum int, restored bool) {
nseReg2 := defaultRegistryEndpoint(nsReg.Name)
nseReg2.Name += "-2"

domain.Nodes[2].NewEndpoint(ctx, nseReg2, sandbox.GenerateTestToken, counter)
domain.Nodes[2].NewEndpoint(ctx, nseReg2, sandbox.DefaultTokenTimeout, counter)
}

nsmgrCtxCancel()
Expand All @@ -287,7 +287,7 @@ func testNSMGRHealNSMgr(t *testing.T, nodeNum int, restored bool) {
return grpcutils.CheckURLFree(domain.Nodes[0].NSMgr.URL)
}, timeout, tick)

domain.Nodes[nodeNum].NewNSMgr(ctx, mgr.Name, mgr.URL, sandbox.GenerateTestToken, nsmgr.NewServer)
domain.Nodes[nodeNum].NewNSMgr(ctx, mgr.Name, mgr.URL, sandbox.DefaultTokenTimeout, nsmgr.NewServer)
}

if restored {
Expand Down Expand Up @@ -323,11 +323,11 @@ func testNSMGRHealNSMgr(t *testing.T, nodeNum int, restored bool) {
func setupCancellableNSMgrNode(ctx context.Context, node *sandbox.Node) context.CancelFunc {
nsmgrCtx, nsmgrCtxCancel := context.WithCancel(ctx)

node.NewNSMgr(nsmgrCtx, sandbox.UniqueName("nsmgr"), nil, sandbox.GenerateTestToken, nsmgr.NewServer)
node.NewNSMgr(nsmgrCtx, sandbox.UniqueName("nsmgr"), nil, sandbox.DefaultTokenTimeout, nsmgr.NewServer)

node.NewForwarder(ctx, &registry.NetworkServiceEndpoint{
Name: sandbox.UniqueName("forwarder"),
}, sandbox.GenerateTestToken)
}, sandbox.DefaultTokenTimeout)

return nsmgrCtxCancel
}
Expand All @@ -344,20 +344,20 @@ func TestNSMGR_CloseHeal(t *testing.T) {
SetRegistryProxySupplier(nil).
Build()

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.DefaultTokenTimeout)

nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService())
require.NoError(t, err)

nseCtx, nseCtxCancel := context.WithCancel(ctx)

domain.Nodes[0].NewEndpoint(nseCtx, defaultRegistryEndpoint(nsReg.Name), sandbox.GenerateTestToken)
domain.Nodes[0].NewEndpoint(nseCtx, defaultRegistryEndpoint(nsReg.Name), sandbox.DefaultTokenTimeout)

request := defaultRequest(nsReg.Name)

nscCtx, nscCtxCancel := context.WithCancel(ctx)

nsc := domain.Nodes[0].NewClient(nscCtx, sandbox.GenerateTestToken)
nsc := domain.Nodes[0].NewClient(nscCtx, sandbox.DefaultTokenTimeout)

// 1. Request
conn, err := nsc.Request(ctx, request.Clone())
Expand Down
8 changes: 4 additions & 4 deletions pkg/networkservice/chains/nsmgr/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestCreateEndpointDuringRequest(t *testing.T) {
SetRegistryProxySupplier(nil).
Build()

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.DefaultTokenTimeout)

nsReg := &registry.NetworkService{
Name: "ns-1",
Expand Down Expand Up @@ -95,9 +95,9 @@ func TestCreateEndpointDuringRequest(t *testing.T) {
},
}

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

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

// check first request
conn, err := nsc.Request(ctx, &networkservice.NetworkServiceRequest{
Expand Down Expand Up @@ -139,7 +139,7 @@ func (m *nseMaker) Request(_ context.Context, _ *networkservice.NetworkServiceRe
return nil, errors.New("can't create new endpoint")
}

m.domain.Nodes[1].NewEndpoint(m.ctx, m.nseReg, sandbox.GenerateTestToken, endpoint)
m.domain.Nodes[1].NewEndpoint(m.ctx, m.nseReg, sandbox.DefaultTokenTimeout, endpoint)

return nil, errors.New("can't provide requested network service")
}
Expand Down
30 changes: 15 additions & 15 deletions pkg/networkservice/chains/nsmgr/single_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ func Test_DNSUsecase(t *testing.T) {
SetRegistryProxySupplier(nil).
Build()

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.DefaultTokenTimeout)

nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService())
require.NoError(t, err)

nseReg := defaultRegistryEndpoint(nsReg.Name)

nse := domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, dnscontext.NewServer(
nse := domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.DefaultTokenTimeout, dnscontext.NewServer(
&networkservice.DNSConfig{
DnsServerIps: []string{"8.8.8.8"},
SearchDomains: []string{"my.domain1"},
Expand All @@ -75,7 +75,7 @@ func Test_DNSUsecase(t *testing.T) {

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

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, dnscontext.NewClient(
nsc := domain.Nodes[0].NewClient(ctx, sandbox.DefaultTokenTimeout, dnscontext.NewClient(
dnscontext.WithChainContext(ctx),
dnscontext.WithCorefilePath(corefilePath),
dnscontext.WithResolveConfigPath(resolveConfigPath),
Expand Down Expand Up @@ -110,12 +110,12 @@ func Test_ShouldCorrectlyAddForwardersWithSameNames(t *testing.T) {
SetNodesCount(1).
SetRegistryProxySupplier(nil).
SetNodeSetup(func(ctx context.Context, node *sandbox.Node, _ int) {
node.NewNSMgr(ctx, "nsmgr", nil, sandbox.GenerateTestToken, nsmgr.NewServer)
node.NewNSMgr(ctx, "nsmgr", nil, sandbox.DefaultTokenTimeout, nsmgr.NewServer)
}).
SetRegistryExpiryDuration(sandbox.RegistryExpiryDuration).
Build()

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.DefaultTokenTimeout)

nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService())
require.NoError(t, err)
Expand All @@ -129,7 +129,7 @@ func Test_ShouldCorrectlyAddForwardersWithSameNames(t *testing.T) {
var forwarders [3]*sandbox.EndpointEntry
for i := range forwarderRegs {
forwarderRegs[i] = forwarderReg.Clone()
forwarders[i] = domain.Nodes[0].NewForwarder(ctx, forwarderRegs[i], sandbox.GenerateTestToken)
forwarders[i] = domain.Nodes[0].NewForwarder(ctx, forwarderRegs[i], sandbox.DefaultTokenTimeout)
}

// 2. Wait for refresh
Expand Down Expand Up @@ -158,7 +158,7 @@ func Test_ShouldCorrectlyAddEndpointsWithSameNames(t *testing.T) {
SetRegistryExpiryDuration(sandbox.RegistryExpiryDuration).
Build()

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.DefaultTokenTimeout)

// 1. Add endpoints
var nseRegs [2]*registry.NetworkServiceEndpoint
Expand All @@ -170,14 +170,14 @@ func Test_ShouldCorrectlyAddEndpointsWithSameNames(t *testing.T) {
nseRegs[i] = defaultRegistryEndpoint(nsReg.Name)
nseRegs[i].NetworkServiceNames[0] = nsReg.Name

nses[i] = domain.Nodes[0].NewEndpoint(ctx, nseRegs[i], sandbox.GenerateTestToken)
nses[i] = domain.Nodes[0].NewEndpoint(ctx, nseRegs[i], sandbox.DefaultTokenTimeout)
}

// 2. Wait for refresh
<-time.After(sandbox.RegistryExpiryDuration)

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

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

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.DefaultTokenTimeout)

nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService())
require.NoError(t, err)
Expand All @@ -218,9 +218,9 @@ func Test_Local_NoURLUsecase(t *testing.T) {
request := defaultRequest(nsReg.Name)
counter := &counterServer{}

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

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

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

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.DefaultTokenTimeout)

nsReg := defaultRegistryService()
nsReg.Matches = []*registry.Match{
Expand All @@ -290,9 +290,9 @@ func Test_ShouldParseNetworkServiceLabelsTemplate(t *testing.T) {
nseReg := defaultRegistryEndpoint(nsReg.Name)
nseReg.NetworkServiceLabels = map[string]*registry.NetworkServiceLabels{nsReg.Name: {}}

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

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

req := defaultRequest(nsReg.Name)
Expand Down
Loading