Skip to content

Commit

Permalink
Better error message for Health Check Failure (#1222)
Browse files Browse the repository at this point in the history
Includes more e2e and unit tests to cover
this scenario.

Should improve experience in #1217
  • Loading branch information
markmandel authored and roberthbailey committed Dec 19, 2019
1 parent 64ceb4d commit 1161b40
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/sdkserver/sdkserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ func (s *SDKServer) updateState() error {
switch gs.Status.State {
case agonesv1.GameServerStateUnhealthy:
level = corev1.EventTypeWarning
message = "Health check failure"
case agonesv1.GameServerStateReserved:
s.gsUpdateMutex.Lock()
if s.gsReserveDuration != nil {
Expand Down
41 changes: 41 additions & 0 deletions pkg/sdkserver/sdkserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,47 @@ func TestSidecarHealthLastUpdated(t *testing.T) {
wg.Wait()
}

func TestSidecarUnhealthyMessage(t *testing.T) {
t.Parallel()

m := agtesting.NewMocks()
sc, err := NewSDKServer("test", "default", m.KubeClient, m.AgonesClient)
assert.NoError(t, err)

m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) {
gs := agonesv1.GameServer{
ObjectMeta: metav1.ObjectMeta{
Name: "test", Namespace: "default",
},
Spec: agonesv1.GameServerSpec{},
Status: agonesv1.GameServerStatus{
State: agonesv1.GameServerStateStarting,
},
}
gs.ApplyDefaults()
return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{gs}}, nil
})

stop := make(chan struct{})
defer close(stop)

sc.informerFactory.Start(stop)
assert.True(t, cache.WaitForCacheSync(stop, sc.gameServerSynced))

sc.recorder = m.FakeRecorder

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
err := sc.Run(ctx.Done())
assert.Nil(t, err)
}()

// manually push through an unhealthy state change
sc.enqueueState(agonesv1.GameServerStateUnhealthy)
agtesting.AssertEventContains(t, m.FakeRecorder.Events, "Health check failure")
}

func TestSidecarHealthy(t *testing.T) {
t.Parallel()

Expand Down
16 changes: 16 additions & 0 deletions test/e2e/gameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ func TestSDKSetAnnotation(t *testing.T) {
assert.NotEmpty(t, gs.ObjectMeta.Annotations[agonesv1.VersionAnnotation])
}

func TestUnhealthyGameServerAfterHealthCheckFail(t *testing.T) {
t.Parallel()
gs := defaultGameServer(defaultNs)
gs.Spec.Health.FailureThreshold = 1

gs, err := framework.CreateGameServerAndWaitUntilReady(defaultNs, gs)
assert.NoError(t, err)

reply, err := e2eframework.SendGameServerUDP(gs, "UNHEALTHY")
assert.NoError(t, err)
assert.Equal(t, "ACK: UNHEALTHY\n", reply)

_, err = framework.WaitForGameServerState(gs, agonesv1.GameServerStateUnhealthy, time.Minute)
assert.NoError(t, err)
}

func TestUnhealthyGameServersWithoutFreePorts(t *testing.T) {
t.Parallel()
nodes, err := framework.KubeClient.CoreV1().Nodes().List(metav1.ListOptions{})
Expand Down

0 comments on commit 1161b40

Please sign in to comment.