-
Notifications
You must be signed in to change notification settings - Fork 811
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
markmandel
merged 2 commits into
googleforgames:master
from
aLekSer:fix/flaky-local-sdk-test
May 26, 2020
Merged
Fix flaky Local SDK test #1586
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,9 @@ func TestLocalSDKServerSetLabel(t *testing.T) { | |
} | ||
|
||
for k, v := range fixtures { | ||
// pin variables here, see scopelint for details | ||
k := k | ||
v := v | ||
t.Run(k, func(t *testing.T) { | ||
ctx := context.Background() | ||
e := &sdk.Empty{} | ||
|
@@ -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"} | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
@@ -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) | ||
|
@@ -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") | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 timeThere was a problem hiding this comment.
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.