Skip to content

Commit

Permalink
Fixed flaky TestGameServerWithPortsMappedToMultipleContainers (#1458)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-kremsa-globant authored Apr 11, 2020
1 parent 08f6679 commit c9c5399
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions test/e2e/gameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package e2e
import (
"fmt"
"net"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -480,17 +481,19 @@ func TestGameServerWithPortsMappedToMultipleContainers(t *testing.T) {
t.Parallel()
firstContainerName := "udp-server"
secondContainerName := "second-udp-server"
firstPort := "gameport"
secondPort := "second-gameport"
gs := &agonesv1.GameServer{ObjectMeta: metav1.ObjectMeta{GenerateName: "udp-server", Namespace: defaultNs},
Spec: agonesv1.GameServerSpec{
Container: firstContainerName,
Ports: []agonesv1.GameServerPort{{
ContainerPort: 7654,
Name: "gameport",
Name: firstPort,
PortPolicy: agonesv1.Dynamic,
Protocol: corev1.ProtocolUDP,
}, {
ContainerPort: 5000,
Name: "second-gameport",
Name: secondPort,
PortPolicy: agonesv1.Dynamic,
Protocol: corev1.ProtocolUDP,
Container: &secondContainerName,
Expand Down Expand Up @@ -522,17 +525,31 @@ func TestGameServerWithPortsMappedToMultipleContainers(t *testing.T) {
defer framework.AgonesClient.AgonesV1().GameServers(defaultNs).Delete(readyGs.ObjectMeta.Name, nil) // nolint: errcheck
assert.Equal(t, readyGs.Status.State, agonesv1.GameServerStateReady)

firstContainerReply, err := e2eframework.SendGameServerUDPToPort(readyGs, "gameport", "Ping 1")
if err != nil {
t.Fatalf("Could not message GameServer: %v", err)
}
assert.Contains(t, firstContainerReply, "Ping 1")
interval := 2 * time.Second
timeOut := 60 * time.Second

secondContainerReply, err := e2eframework.SendGameServerUDPToPort(readyGs, "second-gameport", "Ping 2")
if err != nil {
t.Fatalf("Could not message GameServer: %v", err)
expectedMsg1 := "Ping 1"
errPoll := wait.PollImmediate(interval, timeOut, func() (done bool, err error) {
res, err := e2eframework.SendGameServerUDPToPort(readyGs, firstPort, expectedMsg1)
if err != nil {
t.Logf("Could not message GameServer on %s: %v. Will try again...", firstPort, err)
}
return err == nil && strings.Contains(res, expectedMsg1), nil
})
if errPoll != nil {
assert.FailNow(t, errPoll.Error(), "expected no errors after polling a port: %s", firstPort)
}
assert.Contains(t, secondContainerReply, "Ping 2")

expectedMsg2 := "Ping 2"
errPoll = wait.PollImmediate(interval, timeOut, func() (done bool, err error) {
res, err := e2eframework.SendGameServerUDPToPort(readyGs, secondPort, expectedMsg2)
if err != nil {
t.Logf("Could not message GameServer on %s: %v. Will try again...", secondPort, err)
}
return err == nil && strings.Contains(res, expectedMsg2), nil
})

assert.NoError(t, errPoll, "expected no errors after polling a port: %s", secondPort)
}

func TestGameServerReserve(t *testing.T) {
Expand Down

0 comments on commit c9c5399

Please sign in to comment.