Skip to content

Commit

Permalink
add retries
Browse files Browse the repository at this point in the history
Signed-off-by: denis-tingaikin <denis.tingajkin@xored.com>
  • Loading branch information
denis-tingaikin committed Nov 10, 2021
1 parent fc26ff2 commit 3048929
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 25 deletions.
63 changes: 47 additions & 16 deletions internal/tests/suite_combinatronics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ package tests

import (
"context"
"io/ioutil"
"net"
"net/url"
"os"
"path/filepath"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -108,14 +112,18 @@ func (f *ForwarderTestSuite) TestCombinations() {
payload.IP: {
kernel.MECHANISM,
memif.MECHANISM,
// wireguard.MECHANISM,
wireguard.MECHANISM,
},
payload.Ethernet: {
kernel.MECHANISM,
memif.MECHANISM,
// vxlan.MECHANISM,
vxlan.MECHANISM,
},
}
isRemote := map[string]bool{
wireguard.MECHANISM: true,
vxlan.MECHANISM: true,
}
for _, pl := range []string{payload.Ethernet, payload.IP} {
payloadName := pl
f.T().Run(strings.Title(strings.ToLower(payloadName)), func(t *testing.T) {
Expand All @@ -133,20 +141,16 @@ func (f *ForwarderTestSuite) TestCombinations() {
defer cancel()
ctx = log.WithFields(ctx, map[string]interface{}{"test": t.Name()})
ctx = log.WithLog(ctx, logruslogger.New(ctx))
networkserviceName := "ns"
networkserviceName := "ns" + t.Name()

_, err = adapters.NetworkServiceEndpointServerToClient(f.registryServer).Register(ctx, &registry.NetworkServiceEndpoint{
Name: "nse",
NetworkServiceNames: []string{"ns"},
Url: f.config.ConnectTo.String(),
})
tmpDir, err := ioutil.TempDir("", "nse")
f.Require().NoError(err)
defer func(tmpDir string) { _ = os.Remove(tmpDir) }(tmpDir)
nseURL := url.URL{Scheme: "unix", Path: filepath.Join(tmpDir, "listen.on")}

_, err = adapters.NetworkServiceServerToClient(f.registryNSServer).Register(ctx, &registry.NetworkService{
Name: "ns",
Payload: payloadName,
})
f.Require().NoError(err)
if isRemote[endpointMechanism] {
nseURL = url.URL{Scheme: "tcp", Host: "127.0.0.1:0"}
}

testRequest := &networkservice.NetworkServiceRequest{
Connection: &networkservice.Connection{
Expand All @@ -164,11 +168,38 @@ func (f *ForwarderTestSuite) TestCombinations() {
ep := epFunc(ctx)
networkservice.RegisterNetworkServiceServer(server, ep)
networkservice.RegisterMonitorConnectionServer(server, ep)
registry.RegisterNetworkServiceEndpointRegistryServer(server, f.registryServer)
registry.RegisterNetworkServiceRegistryServer(server, f.registryNSServer)
serverErrCh := f.ListenAndServe(ctx, server)

var serverErrCh <-chan error
var cancel2 func()

for {
var ctx2 context.Context
ctx2, cancel2 = context.WithCancel(f.ctx)
serverErrCh = f.ListenAndServe(ctx2, &nseURL, server)
if nseURL.Host != "127.0.0.1:0" {
break
}
cancel2()
}
defer cancel2()

log.FromContext(ctx).Infof("Launching %s test server (took : %s)", t.Name(), time.Since(now))

_, err = adapters.NetworkServiceEndpointServerToClient(f.registryServer).Register(ctx, &registry.NetworkServiceEndpoint{
Name: "nse-" + t.Name(),
NetworkServiceNames: []string{networkserviceName},
Url: nseURL.String(),
})
f.Require().NoError(err)

_, err = adapters.NetworkServiceServerToClient(f.registryNSServer).Register(ctx, &registry.NetworkService{
Name: networkserviceName,
Payload: payloadName,
})
f.Require().NoError(err)

log.FromContext(ctx).Infof("Registered ns and nse for server %s (took : %s)", t.Name(), time.Since(now))

// ********************************************************************************
log.FromContext(f.ctx).Infof("Sending Request to forwarder (time since start: %s)", time.Since(starttime))
// ********************************************************************************
Expand Down
10 changes: 3 additions & 7 deletions internal/tests/suite_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (f *ForwarderTestSuite) SetupSuite() {
logrus.SetFormatter(&nested.Formatter{})
logrus.SetLevel(logrus.DebugLevel)
log.EnableTracing(true)
f.ctx, f.cancel = context.WithCancel(context.Background())
f.ctx, f.cancel = context.WithTimeout(context.Background(), time.Minute*2)
f.ctx = log.WithLog(f.ctx, logruslogger.New(f.ctx))

starttime := time.Now()
Expand Down Expand Up @@ -147,12 +147,8 @@ func (f *ForwarderTestSuite) SetupSuite() {
registry.RegisterNetworkServiceEndpointRegistryServer(server, f.registryServer)
registry.RegisterNetworkServiceRegistryServer(server, f.registryNSServer)

ctx, cancel := context.WithCancel(f.ctx)
defer func(cancel context.CancelFunc, serverErrCh <-chan error) {
cancel()
err = <-serverErrCh
f.Require().NoError(err)
}(cancel, f.ListenAndServe(ctx, server))
f.Require().Len(f.ListenAndServe(f.ctx, &f.config.ConnectTo, server), 0)
ctx := f.ctx

recv, err := adapters.NetworkServiceEndpointServerToClient(memrg).Find(ctx, &registry.NetworkServiceEndpointQuery{
NetworkServiceEndpoint: &registry.NetworkServiceEndpoint{
Expand Down
5 changes: 3 additions & 2 deletions internal/tests/suite_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package tests
import (
"context"
"net"
"net/url"
"time"

"github.com/pkg/errors"
Expand All @@ -37,8 +38,8 @@ const (
serverIP = "10.0.2.3"
)

func (f *ForwarderTestSuite) ListenAndServe(ctx context.Context, server *grpc.Server) <-chan error {
errCh := grpcutils.ListenAndServe(ctx, &f.config.ConnectTo, server)
func (f *ForwarderTestSuite) ListenAndServe(ctx context.Context, listenOn *url.URL, server *grpc.Server) <-chan error {
errCh := grpcutils.ListenAndServe(ctx, listenOn, server)
select {
case err, ok := <-errCh:
f.Require().True(ok)
Expand Down

0 comments on commit 3048929

Please sign in to comment.