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

Fix flaky Local SDK test #1586

Merged
merged 2 commits into from
May 26, 2020
Merged
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
24 changes: 20 additions & 4 deletions pkg/sdkserver/localsdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ func TestLocalSDKServerSetLabel(t *testing.T) {
}

for k, v := range fixtures {
// pin variables here, see scopelint for details
k := k
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this before, and I feel like I've done similar to fix previous issues and I forget the reason for it. Can we add a note explaining?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will do (there is a gocritic linter article about this), btw on the multiple runs still get some errors. Will update the test one more time

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not gocritic, but https://github.com/kyoh86/scopelint and it is obsolete, with two successors.

v := v
t.Run(k, func(t *testing.T) {
ctx := context.Background()
e := &sdk.Empty{}
Expand Down Expand Up @@ -257,6 +260,16 @@ func TestLocalSDKServerWatchGameServer(t *testing.T) {
err := l.WatchGameServer(e, stream)
assert.Nil(t, err)
}()
// wait for watching to begin
err = wait.Poll(time.Second, 10*time.Second, func() (bool, error) {
found := false
l.updateObservers.Range(func(_, _ interface{}) bool {
found = true
return false
})
return found, nil
})
assert.NoError(t, err)

assertNoWatchUpdate(t, stream)
fixture.ObjectMeta.Annotations = map[string]string{"foo": "bar"}
Expand Down Expand Up @@ -380,9 +393,10 @@ func TestLocalSDKServerPlayerConnectAndDisconnect(t *testing.T) {
}

for k, v := range fixtures {
// pin variables here, see https://github.com/kyoh86/scopelint for the details
k := k
v := v
t.Run(k, func(t *testing.T) {
t.Parallel()
Copy link
Collaborator Author

@aLekSer aLekSer May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line leads to unpredictable behaviour. I assume we can add this back in a separate PR.


var l *LocalSDKServer
var err error
if v.useFile {
Expand Down Expand Up @@ -428,7 +442,9 @@ func TestLocalSDKServerPlayerConnectAndDisconnect(t *testing.T) {
id := &alpha.PlayerID{PlayerID: "one"}
ok, err := l.IsPlayerConnected(context.Background(), id)
assert.NoError(t, err)
assert.False(t, ok.Bool, "player should not be connected")
if assert.NotNil(t, ok) {
assert.False(t, ok.Bool, "player should not be connected")
}

count, err := l.GetPlayerCount(context.Background(), e)
assert.NoError(t, err)
Expand Down Expand Up @@ -630,7 +646,7 @@ func assertWatchUpdate(t *testing.T, stream *gameServerMockStream, expected inte
select {
case msg := <-stream.msgs:
assert.Equal(t, expected, actual(msg))
case <-time.After(10 * time.Second):
case <-time.After(20 * time.Second):
assert.Fail(t, "timeout on receiving messages")
}
}
Expand Down