Skip to content

Commit

Permalink
Flaky: TestSDKServerWatchGameServerFeatureSDKWatchSendOnExecute (#1667)
Browse files Browse the repository at this point in the history
* Flaky: TestSDKServerWatchGameServerFeatureSDKWatchSendOnExecute

Switching default: case to a timeout, since due to the asynchronous
nature of event processing, it could take a moment or two for the extra
event to be processed.

This is particularly true on the CI system, where there is a lot of
processing going on, and it may take more time than usual to process.
  • Loading branch information
markmandel authored Jul 1, 2020
1 parent b9825c9 commit ad9cc14
Showing 1 changed file with 26 additions and 11 deletions.
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())
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
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

0 comments on commit ad9cc14

Please sign in to comment.