Skip to content

Commit

Permalink
Revert "fix combine tests"
Browse files Browse the repository at this point in the history
This reverts commit b1509d1.

Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Jan 15, 2024
1 parent 18b8b70 commit e5fc986
Showing 1 changed file with 37 additions and 58 deletions.
95 changes: 37 additions & 58 deletions pkg/networkservice/chains/endpoint/combine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package endpoint_test

import (
"context"
"io"
"net/url"
"testing"
"time"
Expand All @@ -29,6 +30,8 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"

"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/memif"
Expand All @@ -39,7 +42,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/monitor"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/updatepath"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
)

Expand Down Expand Up @@ -83,23 +85,14 @@ func testCombine(t *testing.T, mechanism *networkservice.Mechanism) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

var m networkservice.MonitorConnectionServer
e := endpoint.Combine(func(servers []networkservice.NetworkServiceServer) networkservice.NetworkServiceServer {
return next.NewNetworkServiceServer(
begin.NewServer(),
metadata.NewServer(),
monitor.NewServer(ctx, &m),
mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
kernel.MECHANISM: servers[0],
memif.MECHANISM: servers[1],
}))
}, newTestEndpoint(kernel.MECHANISM), newTestEndpoint(memif.MECHANISM))

combined := &testEndpoint{
NetworkServiceServer: e,
MonitorConnectionServer: m,
}
cc := startEndpoint(ctx, t, combined)
return mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
kernel.MECHANISM: servers[0],
memif.MECHANISM: servers[1],
})
}, newTestEndpoint(ctx, kernel.MECHANISM), newTestEndpoint(ctx, memif.MECHANISM))

cc := startEndpoint(ctx, t, e)
defer func() { _ = cc.Close() }()

c := next.NewNetworkServiceClient(
Expand Down Expand Up @@ -132,11 +125,11 @@ func testCombine(t *testing.T, mechanism *networkservice.Mechanism) {
require.Equal(t, (&networkservice.ConnectionEvent{
Type: networkservice.ConnectionEventType_UPDATE,
Connections: map[string]*networkservice.Connection{
conn.GetCurrentPathSegment().GetId(): {
Id: conn.GetCurrentPathSegment().GetId(),
conn.GetNextPathSegment().GetId(): {
Id: conn.GetNextPathSegment().GetId(),
Mechanism: conn.GetMechanism(),
Path: &networkservice.Path{
Index: 0,
Index: 1,
PathSegments: conn.GetPath().GetPathSegments(),
},
},
Expand Down Expand Up @@ -170,24 +163,14 @@ func TestSwitchEndpoint_InitialStateTransfer(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

var m networkservice.MonitorConnectionServer
e := endpoint.Combine(func(servers []networkservice.NetworkServiceServer) networkservice.NetworkServiceServer {
return next.NewNetworkServiceServer(
begin.NewServer(),
metadata.NewServer(),
monitor.NewServer(ctx, &m),
mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
kernel.MECHANISM: servers[0],
memif.MECHANISM: servers[1],
}))
}, newTestEndpoint(kernel.MECHANISM), newTestEndpoint(memif.MECHANISM))

combined := &testEndpoint{
NetworkServiceServer: e,
MonitorConnectionServer: m,
}
return mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
kernel.MECHANISM: servers[0],
memif.MECHANISM: servers[1],
})
}, newTestEndpoint(ctx, kernel.MECHANISM), newTestEndpoint(ctx, memif.MECHANISM))

cc := startEndpoint(ctx, t, combined)
cc := startEndpoint(ctx, t, e)
defer func() { _ = cc.Close() }()

c := next.NewNetworkServiceClient(
Expand All @@ -214,11 +197,11 @@ func TestSwitchEndpoint_InitialStateTransfer(t *testing.T) {
Connections: make(map[string]*networkservice.Connection),
}
for _, conn := range conns {
expectedEvent.Connections[conn.GetCurrentPathSegment().GetId()] = &networkservice.Connection{
Id: conn.GetCurrentPathSegment().GetId(),
expectedEvent.Connections[conn.GetNextPathSegment().GetId()] = &networkservice.Connection{
Id: conn.GetNextPathSegment().GetId(),
Mechanism: conn.GetMechanism(),
Path: &networkservice.Path{
Index: 0,
Index: 1,
PathSegments: conn.GetPath().GetPathSegments(),
},
}
Expand Down Expand Up @@ -246,25 +229,15 @@ func TestSwitchEndpoint_DuplicateEndpoints(t *testing.T) {

monitorCtx, cancelMonitor := context.WithCancel(ctx)

duplicate := newTestEndpoint("duplicate")
var m networkservice.MonitorConnectionServer
duplicate := newTestEndpoint(monitorCtx, "duplicate")
e := endpoint.Combine(func(servers []networkservice.NetworkServiceServer) networkservice.NetworkServiceServer {
return next.NewNetworkServiceServer(
begin.NewServer(),
metadata.NewServer(),
monitor.NewServer(monitorCtx, &m),
mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
kernel.MECHANISM: servers[0],
memif.MECHANISM: servers[1],
}))
return mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
kernel.MECHANISM: servers[0],
memif.MECHANISM: servers[1],
})
}, duplicate, duplicate)

combined := &testEndpoint{
NetworkServiceServer: e,
MonitorConnectionServer: m,
}

cc := startEndpoint(ctx, t, combined)
cc := startEndpoint(ctx, t, e)
defer func() { _ = cc.Close() }()

c := next.NewNetworkServiceClient(
Expand Down Expand Up @@ -295,11 +268,11 @@ func TestSwitchEndpoint_DuplicateEndpoints(t *testing.T) {
require.Equal(t, (&networkservice.ConnectionEvent{
Type: networkservice.ConnectionEventType_UPDATE,
Connections: map[string]*networkservice.Connection{
conn.GetCurrentPathSegment().GetId(): {
Id: conn.GetCurrentPathSegment().GetId(),
conn.GetNextPathSegment().GetId(): {
Id: conn.GetNextPathSegment().GetId(),
Mechanism: conn.GetMechanism(),
Path: &networkservice.Path{
Index: 0,
Index: 1,
PathSegments: conn.GetPath().GetPathSegments(),
},
},
Expand Down Expand Up @@ -329,6 +302,9 @@ func TestSwitchEndpoint_DuplicateEndpoints(t *testing.T) {
}

cancelMonitor()

_, err = stream.Recv()
require.ErrorIs(t, err, io.EOF)
}

type testEndpoint struct {
Expand All @@ -340,6 +316,9 @@ func newTestEndpoint(name string) *testEndpoint {
e := new(testEndpoint)
e.NetworkServiceServer = next.NewNetworkServiceServer(
updatepath.NewServer(name),
begin.NewServer(),
metadata.NewServer(),
monitor.NewServer(ctx, &e.MonitorConnectionServer),
)
return e
}
Expand Down

0 comments on commit e5fc986

Please sign in to comment.