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

E2E Cleanup: Implement SendGameServerUDP #644

Merged
merged 2 commits into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,16 @@ func (f *Framework) CleanUp(ns string) error {
DeleteCollection(deleteOptions, listOptions)
}

// PingGameServer pings a gameserver and returns its reply
func PingGameServer(msg, address string) (reply string, err error) {
// SendGameServerUDP sends a message to a gameserver and returns its reply
// assumes the first port is the port to send the message to
func SendGameServerUDP(gs *v1alpha1.GameServer, msg string) (string, error) {
address := fmt.Sprintf("%s:%d", gs.Status.Address, gs.Status.Ports[0].Port)
return SendUDP(address, msg)
}

// SendUDP sends a message to an address, and returns its reply if
// it returns one in 30 seconds
func SendUDP(address, msg string) (string, error) {
conn, err := net.Dial("udp", address)
if err != nil {
return "", err
Expand Down
13 changes: 4 additions & 9 deletions test/e2e/gameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package e2e

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -48,8 +47,7 @@ func TestCreateConnect(t *testing.T) {
assert.NotEmpty(t, readyGs.Status.NodeName)
assert.Equal(t, readyGs.Status.State, v1alpha1.GameServerStateReady)

reply, err := e2eframework.PingGameServer("Hello World !", fmt.Sprintf("%s:%d", readyGs.Status.Address,
readyGs.Status.Ports[0].Port))
reply, err := e2eframework.SendGameServerUDP(readyGs, "Hello World !")

if err != nil {
t.Fatalf("Could ping GameServer: %v", err)
Expand All @@ -68,8 +66,7 @@ func TestSDKSetLabel(t *testing.T) {
}

assert.Equal(t, readyGs.Status.State, v1alpha1.GameServerStateReady)
reply, err := e2eframework.PingGameServer("LABEL", fmt.Sprintf("%s:%d", readyGs.Status.Address,
readyGs.Status.Ports[0].Port))
reply, err := e2eframework.SendGameServerUDP(readyGs, "LABEL")

if err != nil {
t.Fatalf("Could ping GameServer: %v", err)
Expand Down Expand Up @@ -105,8 +102,7 @@ func TestHealthCheckDisable(t *testing.T) {
}
defer framework.AgonesClient.StableV1alpha1().GameServers(defaultNs).Delete(readyGs.ObjectMeta.Name, nil) // nolint: errcheck

_, err = e2eframework.PingGameServer("UNHEALTHY", fmt.Sprintf("%s:%d", readyGs.Status.Address,
readyGs.Status.Ports[0].Port))
_, err = e2eframework.SendGameServerUDP(readyGs, "UNHEALTHY")

if err != nil {
t.Fatalf("Could not ping GameServer: %v", err)
Expand Down Expand Up @@ -134,8 +130,7 @@ func TestSDKSetAnnotation(t *testing.T) {
defer framework.AgonesClient.StableV1alpha1().GameServers(defaultNs).Delete(readyGs.ObjectMeta.Name, nil) // nolint: errcheck

assert.Equal(t, readyGs.Status.State, v1alpha1.GameServerStateReady)
reply, err := e2eframework.PingGameServer("ANNOTATION", fmt.Sprintf("%s:%d", readyGs.Status.Address,
readyGs.Status.Ports[0].Port))
reply, err := e2eframework.SendGameServerUDP(readyGs, "ANNOTATION")

if err != nil {
t.Fatalf("Could ping GameServer: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestPingUDP(t *testing.T) {
assert.Nil(t, err)

expected := "hello"
reply, err := e2eframework.PingGameServer(expected, fmt.Sprintf("%s:%d", externalIP, p))
reply, err := e2eframework.SendUDP(fmt.Sprintf("%s:%d", externalIP, p), expected)
assert.Nil(t, err)
assert.Equal(t, expected, reply)
}
Expand Down