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

Enabled TestRefreshClient_Sandbox #1181

Closed
wants to merge 1 commit into from
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
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 -run TestRefreshClient_Sandbox -count 20000 -race ./pkg/networkservice/common/refresh -timeout 3h -v
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions pkg/networkservice/common/begin/event_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package begin

import (
"context"
"fmt"

"github.com/edwarnicke/serialize"
"github.com/networkservicemesh/api/pkg/api/networkservice"
Expand Down Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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(),
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/networkservice/common/refresh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package refresh

import (
"context"
"fmt"
"time"

"github.com/golang/protobuf/ptypes"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions pkg/networkservice/common/refresh/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 9 additions & 8 deletions pkg/networkservice/common/refresh/client_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package refresh_test
import (
"context"
"math/rand"
"runtime/debug"
"strconv"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -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
}
Expand All @@ -143,31 +144,31 @@ 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
}

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
}

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 = ""
}

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()))
}
}

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down