From e46cc5c89843a6e08004cede7b4c426eaa80c11c Mon Sep 17 00:00:00 2001 From: Oleg Solodkov Date: Tue, 30 Nov 2021 00:05:59 +0700 Subject: [PATCH] Enabled TestRefreshClient_Sandbox Signed-off-by: Oleg Solodkov --- .github/workflows/ci.yaml | 2 +- .../common/begin/event_factory.go | 5 +++++ pkg/networkservice/common/refresh/client.go | 3 +++ .../common/refresh/client_test.go | 5 ++--- .../common/refresh/client_utils_test.go | 17 +++++++++-------- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ad04c251c..191429c71 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,7 +33,7 @@ jobs: - name: Build run: go build -race ./... - name: Test - run: go test -race ./... + run: go test -run TestRefreshClient_Sandbox -count 20000 -race ./pkg/networkservice/common/refresh -timeout 3h -v golangci-lint: name: golangci-lint runs-on: ubuntu-latest diff --git a/pkg/networkservice/common/begin/event_factory.go b/pkg/networkservice/common/begin/event_factory.go index a4335fa4f..984815904 100644 --- a/pkg/networkservice/common/begin/event_factory.go +++ b/pkg/networkservice/common/begin/event_factory.go @@ -18,6 +18,7 @@ package begin import ( "context" + "fmt" "github.com/edwarnicke/serialize" "github.com/networkservicemesh/api/pkg/api/networkservice" @@ -76,6 +77,7 @@ func newEventFactoryClient(ctx context.Context, afterClose func(), opts ...grpc. } func (f *eventFactoryClient) Request(opts ...Option) <-chan error { + fmt.Println("eventFactoryClient.Request") o := &option{ cancelCtx: context.Background(), } @@ -114,6 +116,7 @@ func (f *eventFactoryClient) Request(opts ...Option) <-chan error { } func (f *eventFactoryClient) Close(opts ...Option) <-chan error { + fmt.Println("eventFactoryClient.Close") o := &option{ cancelCtx: context.Background(), } @@ -169,6 +172,7 @@ func newEventFactoryServer(ctx context.Context, afterClose func()) *eventFactory } func (f *eventFactoryServer) Request(opts ...Option) <-chan error { + fmt.Println("eventFactoryServer.Request") o := &option{ cancelCtx: context.Background(), } @@ -197,6 +201,7 @@ func (f *eventFactoryServer) Request(opts ...Option) <-chan error { } func (f *eventFactoryServer) Close(opts ...Option) <-chan error { + fmt.Println("eventFactoryServer.Close") o := &option{ cancelCtx: context.Background(), } diff --git a/pkg/networkservice/common/refresh/client.go b/pkg/networkservice/common/refresh/client.go index 764574678..f811a3bca 100644 --- a/pkg/networkservice/common/refresh/client.go +++ b/pkg/networkservice/common/refresh/client.go @@ -22,6 +22,7 @@ package refresh import ( "context" + "fmt" "time" "github.com/golang/protobuf/ptypes" @@ -84,8 +85,10 @@ func (t *refreshClient) Request(ctx context.Context, request *networkservice.Net for { select { case <-cancelCtx.Done(): + fmt.Println("Refresh client: cancel done") return case <-afterTicker.C(): + fmt.Println("Refresh client: performing request") if err := <-eventFactory.Request(begin.CancelContext(cancelCtx)); err != nil { logger.Warnf("refresh failed: %s", err.Error()) continue diff --git a/pkg/networkservice/common/refresh/client_test.go b/pkg/networkservice/common/refresh/client_test.go index eadacb91d..1ddaf3375 100644 --- a/pkg/networkservice/common/refresh/client_test.go +++ b/pkg/networkservice/common/refresh/client_test.go @@ -231,8 +231,6 @@ func TestRefreshClient_CheckRaceConditions(t *testing.T) { } func TestRefreshClient_Sandbox(t *testing.T) { - t.Skip("https://github.com/networkservicemesh/sdk/issues/839") - t.Cleanup(func() { goleak.VerifyNone(t) }) ctx, cancel := context.WithTimeout(context.Background(), sandboxTotalTimeout) @@ -270,9 +268,10 @@ func TestRefreshClient_Sandbox(t *testing.T) { refreshSrv.afterRequest() refreshSrv.beforeRequest("test-conn") + require.Eventually(t, func() bool { return refreshSrv.getState() == testRefreshStateDoneRequest - }, sandboxTotalTimeout, sandboxStepDuration) + }, sandboxTotalTimeout, sandboxStepDuration, refreshSrv.getState()) } func TestRefreshClient_NoRefreshOnFailure(t *testing.T) { diff --git a/pkg/networkservice/common/refresh/client_utils_test.go b/pkg/networkservice/common/refresh/client_utils_test.go index 0a3395c31..00ff0c41f 100644 --- a/pkg/networkservice/common/refresh/client_utils_test.go +++ b/pkg/networkservice/common/refresh/client_utils_test.go @@ -19,6 +19,7 @@ package refresh_test import ( "context" "math/rand" + "runtime/debug" "strconv" "sync" "sync/atomic" @@ -134,7 +135,7 @@ func (t *refreshTesterServer) beforeRequest(marker string) { t.mutex.Lock() defer t.mutex.Unlock() t.checkUnlocked() - assert.Contains(t.t, []refreshTesterServerState{testRefreshStateInit, testRefreshStateRunning}, t.state, "Unexpected state") + assert.Containsf(t.t, []refreshTesterServerState{testRefreshStateInit, testRefreshStateRunning}, t.state, "Unexpected state: %v, stack: %v", strconv.Itoa(t.state), string(debug.Stack())) t.state = testRefreshStateWaitRequest t.nextMarker = marker } @@ -143,7 +144,7 @@ func (t *refreshTesterServer) afterRequest() { t.mutex.Lock() defer t.mutex.Unlock() t.checkUnlocked() - assert.Equal(t.t, testRefreshStateDoneRequest, t.state, "Unexpected state") + assert.Equalf(t.t, testRefreshStateDoneRequest, t.state, "Unexpected state: %v, stack: %v", strconv.Itoa(t.state), string(debug.Stack())) t.state = testRefreshStateRunning } @@ -151,7 +152,7 @@ func (t *refreshTesterServer) beforeClose() { t.mutex.Lock() defer t.mutex.Unlock() t.checkUnlocked() - assert.Equal(t.t, testRefreshStateRunning, t.state, "Unexpected state") + assert.Equalf(t.t, testRefreshStateRunning, t.state, "Unexpected state: %v, stack: %v", strconv.Itoa(t.state), string(debug.Stack())) t.state = testRefreshStateWaitClose } @@ -159,7 +160,7 @@ func (t *refreshTesterServer) afterClose() { t.mutex.Lock() defer t.mutex.Unlock() t.checkUnlocked() - assert.Equal(t.t, testRefreshStateDoneClose, t.state, "Unexpected state") + assert.Equalf(t.t, testRefreshStateDoneClose, t.state, "Unexpected state: %v, stack: %v", strconv.Itoa(t.state), string(debug.Stack())) t.state = testRefreshStateInit t.currentMarker = "" } @@ -167,7 +168,7 @@ func (t *refreshTesterServer) afterClose() { func (t *refreshTesterServer) checkUnlocked() { if t.state == testRefreshStateDoneRequest || t.state == testRefreshStateRunning { delta := time.Now().UTC().Sub(t.lastSeen) - assert.Lessf(t.t, int64(delta), int64(t.maxDuration), "Duration expired (too slow) delta=%v max=%v", delta, t.maxDuration) + assert.Lessf(t.t, int64(delta), int64(t.maxDuration), "Duration expired (too slow) delta=%v max=%v stack=%v", delta, t.maxDuration, string(debug.Stack())) } } @@ -201,9 +202,9 @@ func (t *refreshTesterServer) Request(ctx context.Context, request *networkservi case testRefreshStateDoneRequest, testRefreshStateRunning, testRefreshStateWaitClose: assert.Equal(t.t, t.currentMarker, marker, "Unexpected marker") delta := time.Now().UTC().Sub(t.lastSeen) - assert.GreaterOrEqual(t.t, int64(delta), int64(t.minDuration), "Too fast delta=%v min=%v", delta, t.minDuration) + assert.GreaterOrEqual(t.t, int64(delta), int64(t.minDuration), "Too fast delta=%v min=%v stack=%v", delta, t.minDuration, string(debug.Stack())) default: - assert.Fail(t.t, "Unexpected state", t.state) + assert.Failf(t.t, "Unexpected state", "state: %v, stack: %v", strconv.Itoa(t.state), string(debug.Stack())) } t.lastSeen = time.Now() @@ -225,7 +226,7 @@ func (t *refreshTesterServer) Close(ctx context.Context, connection *networkserv }() t.checkUnlocked() - assert.Equal(t.t, testRefreshStateWaitClose, t.state, "Unexpected state") + assert.Equalf(t.t, testRefreshStateWaitClose, t.state, "Unexpected state: %v, stack: %v", strconv.Itoa(t.state), string(debug.Stack())) t.state = testRefreshStateDoneClose t.mutex.Unlock()