Skip to content

Commit

Permalink
* * * TEST * * *
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Popov committed Aug 18, 2021
1 parent 3148d95 commit 09a4629
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Build
run: go build -race ./...
- name: Test
run: go test -race ./...
run: go test -race ./pkg/networkservice/chains/nsmgr/...
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
Expand Down
10 changes: 9 additions & 1 deletion pkg/networkservice/chains/nsmgr/heal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ func TestNSMGR_HealEndpoint(t *testing.T) {
}

for _, sample := range samples {
beforeTest(sample.name)
t.Run(sample.name, func(t *testing.T) {
// nolint:scopelint
testNSMGRHealEndpoint(t, sample.nodeNum)
})
afterTest(sample.name)
}
}

Expand Down Expand Up @@ -126,10 +128,12 @@ func TestNSMGR_HealForwarder(t *testing.T) {
}

for _, sample := range samples {
beforeTest(sample.name)
t.Run(sample.name, func(t *testing.T) {
// nolint:scopelint
testNSMGRHealForwarder(t, sample.nodeNum)
})
afterTest(sample.name)
}
}

Expand Down Expand Up @@ -182,7 +186,7 @@ func testNSMGRHealForwarder(t *testing.T, nodeNum int) {

// Close with old connection
_, err = nsc.Close(ctx, conn)
require.NoError(t, err)
require.NoError(t, err) // FIXME: no client found

require.Equal(t, 2, counter.UniqueRequests())
require.Equal(t, 1, counter.UniqueCloses())
Expand All @@ -206,10 +210,12 @@ func TestNSMGR_HealNSMgr(t *testing.T) {
}

for _, sample := range samples {
beforeTest(sample.name)
t.Run(sample.name, func(t *testing.T) {
// nolint:scopelint
testNSMGRHealNSMgr(t, sample.nodeNum, sample.restored)
})
afterTest(sample.name)
}
}

Expand Down Expand Up @@ -342,10 +348,12 @@ func TestNSMGR_CloseHeal(t *testing.T) {
}

for _, sample := range samples {
beforeTest(sample.name)
t.Run(sample.name, func(t *testing.T) {
// nolint:scopelint
testNSMGRCloseHeal(t, sample.withNSEExpiration)
})
afterTest(sample.name)
}
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/networkservice/chains/nsmgr/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ type nsmgrSuite struct {
nsRegistryClient registry.NetworkServiceRegistryClient
}

func (s *nsmgrSuite) BeforeTest(_, testName string) {
beforeTest(testName)
}

func (s *nsmgrSuite) AfterTest(_, testName string) {
afterTest(testName)
}

func TestNsmgr(t *testing.T) {
suite.Run(t, new(nsmgrSuite))
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/networkservice/chains/nsmgr/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/sandbox"
)

func beforeTest(test string) {
println("===============================================")
println(">> START:", test)
println("===============================================")
}

func afterTest(test string) {
println("===============================================")
println(">> END:", test)
println("===============================================")
}

func defaultRegistryService() *registry.NetworkService {
return &registry.NetworkService{
Name: "ns-" + uuid.New().String(),
Expand Down
17 changes: 14 additions & 3 deletions pkg/networkservice/common/connect/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"

"github.com/networkservicemesh/sdk/pkg/tools/clienturlctx"
"github.com/networkservicemesh/sdk/pkg/tools/clock"
Expand All @@ -45,7 +46,7 @@ type connectClient struct {
initOnce sync.Once
}

func (u *connectClient) init() error {
func (u *connectClient) init(conn *networkservice.Connection) error {
u.initOnce.Do(func() {
clockTime := clock.FromContext(u.ctx)

Expand All @@ -68,6 +69,16 @@ func (u *connectClient) init() error {

u.client = u.clientFactory(u.ctx, cc)

connID := conn.Id
go func() {
var state connectivity.State
for cc.WaitForStateChange(u.ctx, state) {
state = cc.GetState()
println(">>", connID, state.String())
}
println(">>", connID, "CONTEXT CLOSE")
}()

go func() {
<-u.ctx.Done()
_ = cc.Close()
Expand All @@ -78,14 +89,14 @@ func (u *connectClient) init() error {
}

func (u *connectClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) {
if err := u.init(); err != nil {
if err := u.init(request.Connection); err != nil {
return nil, err
}
return u.client.Request(ctx, request, opts...)
}

func (u *connectClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) {
if err := u.init(); err != nil {
if err := u.init(conn); err != nil {
return nil, err
}
return u.client.Close(ctx, conn, opts...)
Expand Down
4 changes: 4 additions & 0 deletions pkg/networkservice/common/connect/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func NewServer(
}

func (s *connectServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (conn *networkservice.Connection, err error) {
println("REQUEST:", request.Connection.Id, request.Connection.GetCurrentPathSegment().Name)

clientURL := clienturlctx.ClientURL(ctx)
if clientURL == nil {
return nil, errors.Errorf("clientURL not found for incoming connection: %+v", request.GetConnection())
Expand Down Expand Up @@ -116,6 +118,8 @@ func (s *connectServer) Request(ctx context.Context, request *networkservice.Net
}

func (s *connectServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) {
println("CLOSE:", conn.Id, conn.GetCurrentPathSegment().Name)

var clientErr error
if connInfo, ok := load(ctx); ok {
connInfo.cancel()
Expand Down

0 comments on commit 09a4629

Please sign in to comment.