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

Flaky: TestSDKServerWatchGameServerFeatureSDKWatchSendOnExecute #1667

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
37 changes: 26 additions & 11 deletions pkg/sdkserver/sdkserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,8 @@ func TestSDKServerWatchGameServerFeatureSDKWatchSendOnExecute(t *testing.T) {
}

m := agtesting.NewMocks()
m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) {
return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{*fixture}}, nil
})
fakeWatch := watch.NewFake()
m.AgonesClient.AddWatchReactor("gameservers", k8stesting.DefaultWatchReactor(fakeWatch, nil))

err := agruntime.ParseFeatures(string(agruntime.FeatureSDKWatchSendOnExecute) + "=true")
if !assert.NoError(t, err) {
Expand All @@ -700,6 +699,8 @@ func TestSDKServerWatchGameServerFeatureSDKWatchSendOnExecute(t *testing.T) {
stop := make(chan struct{})
defer close(stop)
sc.informerFactory.Start(stop)

fakeWatch.Add(fixture.DeepCopy())
Copy link
Member Author

Choose a reason for hiding this comment

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

Using a fake Watch so we can control explicitly when the game server is modified.

assert.True(t, cache.WaitForCacheSync(stop, sc.gameServerSynced))
sc.gsWaitForSync.Done()

Expand All @@ -709,17 +710,31 @@ func TestSDKServerWatchGameServerFeatureSDKWatchSendOnExecute(t *testing.T) {
assert.Nil(t, waitConnectedStreamCount(sc, 1))
assert.Equal(t, stream, sc.connectedStreams[0])

// modify for 2nd event in watch stream
fixture.Status.State = agonesv1.GameServerStateAllocated
Copy link
Member Author

Choose a reason for hiding this comment

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

@roberthbailey @akremsa - I reworked this test to check for:

  1. We get what we expect in events on watch and modification
  2. That we don't get too many events
  3. We can't go into an infinite loop

PTAL, let me know what you think

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice update! I like the way you've updated a select section.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also suggested to use state other than Ready.

fakeWatch.Modify(fixture.DeepCopy())

totalSendCalls := 0
for i := 0; i < 2; i++ {
running := true
for running {
select {
case _, ok := <-stream.msgs:
if ok {
totalSendCalls++
} else {
assert.Fail(t, "Channel is closed!")
case gs := <-stream.msgs:
assert.Equal(t, fixture.ObjectMeta.Name, gs.ObjectMeta.Name)
totalSendCalls++
switch totalSendCalls {
case 1:
assert.Equal(t, string(agonesv1.GameServerStateReady), gs.Status.State)
case 2:
assert.Equal(t, string(agonesv1.GameServerStateAllocated), gs.Status.State)
}
// we shouldn't get more than 2, but let's put an upper bound on this
// just in case we suddenly get way more than we expect.
if totalSendCalls > 10 {
assert.FailNow(t, "We should have only received two events. Got over 10 instead.")
}
default:
t.Log("No gameserver in the stream, moving on.")
case <-time.After(5 * time.Second):
// we can't `break` out of the loop, hence we need `running`.
running = false
}
}

Expand Down