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

Fixed flaky TestGameServerWithPortsMappedToMultipleContainers #1458

Merged
merged 1 commit into from
Apr 11, 2020
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
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