From 768063549ebf38ccdfce1c80698e4d59eadf0e44 Mon Sep 17 00:00:00 2001 From: yoshd Date: Thu, 21 Sep 2023 05:14:07 +0900 Subject: [PATCH 1/9] Add conformance test implementation for C# SDK --- build/build-sdk-images/csharp/Dockerfile | 2 +- .../build-sdk-images/csharp/build-sdk-test.sh | 21 +++ build/includes/sdk.mk | 12 +- test/sdk/csharp/Program.cs | 165 ++++++++++++++++++ test/sdk/csharp/csharp.csproj | 13 ++ 5 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 build/build-sdk-images/csharp/build-sdk-test.sh create mode 100644 test/sdk/csharp/Program.cs create mode 100644 test/sdk/csharp/csharp.csproj diff --git a/build/build-sdk-images/csharp/Dockerfile b/build/build-sdk-images/csharp/Dockerfile index 86ec2d5a70..ac22c4c7d9 100644 --- a/build/build-sdk-images/csharp/Dockerfile +++ b/build/build-sdk-images/csharp/Dockerfile @@ -31,7 +31,7 @@ RUN wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsof RUN apt-get update \ - && apt-get install -y dotnet-sdk-3.1 + && apt-get install -y dotnet-sdk-7.0 # code generation scripts COPY *.sh /root/ diff --git a/build/build-sdk-images/csharp/build-sdk-test.sh b/build/build-sdk-images/csharp/build-sdk-test.sh new file mode 100644 index 0000000000..7cc9f9e77e --- /dev/null +++ b/build/build-sdk-images/csharp/build-sdk-test.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Copyright 2019 Google LLC All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -ex + +cd /go/src/agones.dev/agones/test/sdk/csharp + +dotnet run diff --git a/build/includes/sdk.mk b/build/includes/sdk.mk index 7b4be17d6d..80e482d523 100644 --- a/build/includes/sdk.mk +++ b/build/includes/sdk.mk @@ -180,6 +180,16 @@ run-sdk-conformance-test-rust: # run with feature flags enabled and with RUN_ASYNC=true DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS) -e RUN_ASYNC=true" $(MAKE) run-sdk-conformance-test SDK_FOLDER=rust GRPC_PORT=9004 HTTP_PORT=9104 FEATURE_GATES=PlayerTracking=true TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(ALPHA_CONFORMANCE_TESTS) +run-sdk-conformance-test-csharp: + # run without feature flags + $(MAKE) run-sdk-conformance-test SDK_FOLDER=csharp GRPC_PORT=9005 HTTP_PORT=9105 + # run without feature flags and with RUN_ASYNC=true + DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS) -e RUN_ASYNC=true" $(MAKE) run-sdk-conformance-test SDK_FOLDER=csharp GRPC_PORT=9005 HTTP_PORT=9105 + # run with feature flags enabled + $(MAKE) run-sdk-conformance-test SDK_FOLDER=csharp GRPC_PORT=9005 HTTP_PORT=9105 FEATURE_GATES=PlayerTracking=true TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(ALPHA_CONFORMANCE_TESTS) + # run with feature flags enabled and with RUN_ASYNC=true + DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS) -e RUN_ASYNC=true" $(MAKE) run-sdk-conformance-test SDK_FOLDER=csharp GRPC_PORT=9005 HTTP_PORT=9105 FEATURE_GATES=PlayerTracking=true TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(ALPHA_CONFORMANCE_TESTS) + run-sdk-conformance-test-rest: # (note: the restapi folder doesn't use GRPC_PORT but run-sdk-conformance-no-build defaults it, so we supply a unique value here) # run without feature flags @@ -190,7 +200,7 @@ run-sdk-conformance-test-rest: $(MAKE) run-sdk-command COMMAND=clean SDK_FOLDER=restapi # Run a conformance test for all SDKs supported -run-sdk-conformance-tests: run-sdk-conformance-test-node run-sdk-conformance-test-go run-sdk-conformance-test-rust run-sdk-conformance-test-rest run-sdk-conformance-test-cpp +run-sdk-conformance-tests: run-sdk-conformance-test-node run-sdk-conformance-test-go run-sdk-conformance-test-rust run-sdk-conformance-test-rest run-sdk-conformance-test-cpp run-sdk-conformance-test-csharp # Clean package directories and binary files left # after building conformance tests for all SDKs supported diff --git a/test/sdk/csharp/Program.cs b/test/sdk/csharp/Program.cs new file mode 100644 index 0000000000..fc97934645 --- /dev/null +++ b/test/sdk/csharp/Program.cs @@ -0,0 +1,165 @@ +using Agones; +using Grpc.Core; + +Console.WriteLine("Hello, World!"); + +using var sdk = new AgonesSDK(); +{ + sdk.WatchGameServer((gameServer) => + { + Console.WriteLine("Received GameServer update"); + Console.WriteLine(gameServer); + }); +} + +{ + var status = await sdk.ReadyAsync(); + if (status.StatusCode != StatusCode.OK) + { + Console.Error.WriteLine( + $"Could not send ready message. StatusCode={status.StatusCode}, Detail={status.Detail}"); + Environment.Exit(1); + } +} + +{ + var status = await sdk.ReserveAsync(5); + if (status.StatusCode != StatusCode.OK) + { + Console.Error.WriteLine( + $"Could not send reserve command. StatusCode={status.StatusCode}, Detail={status.Detail}"); + Environment.Exit(1); + } +} + +{ + var status = await sdk.AllocateAsync(); + if (status.StatusCode != StatusCode.OK) + { + Console.Error.WriteLine( + $"Err sending allocate request. StatusCode={status.StatusCode}, Detail={status.Detail}"); + Environment.Exit(1); + } +} + +{ + var status = await sdk.HealthAsync(); + if (status.StatusCode != StatusCode.OK) + { + Console.Error.WriteLine( + $"Could not send health check. StatusCode={status.StatusCode}, Detail={status.Detail}"); + Environment.Exit(1); + } +} + +{ + var gameServer = await sdk.GetGameServerAsync(); + Console.WriteLine("Successfully GameServer"); + Console.WriteLine(gameServer); +} + +{ + var status = await sdk.SetLabelAsync("labelKey1", "labelValue1"); + if (status.StatusCode != StatusCode.OK) + { + Console.Error.WriteLine( + $"Could not set label. StatusCode={status.StatusCode}, Detail={status.Detail}"); + Environment.Exit(1); + } +} + +{ + var status = await sdk.SetAnnotationAsync("annotationKey1", "annotationValue1"); + if (status.StatusCode != StatusCode.OK) + { + Console.Error.WriteLine( + $"Could not set annotation. StatusCode={status.StatusCode}, Detail={status.Detail}"); + Environment.Exit(1); + } +} + +var featureGates = Environment.GetEnvironmentVariable("FEATURE_GATES") ?? ""; +if (featureGates.Contains("PlayerTracking")) +{ + var alpha = sdk.Alpha(); + var capacity = 10; + var playerId = "1234"; + + { + var status = await alpha.SetPlayerCapacityAsync(capacity); + if (status.StatusCode != StatusCode.OK) + { + Console.Error.WriteLine( + $"Error setting player capacity. StatusCode={status.StatusCode}, Detail={status.Detail}"); + Environment.Exit(1); + } + } + + { + var c = await alpha.GetPlayerCapacityAsync(); + if (c != capacity) + { + Console.Error.WriteLine( + $"Player Capacity should be {capacity}, but is {c}"); + Environment.Exit(1); + } + } + + { + var ok = await alpha.PlayerConnectAsync(playerId); + if (!ok) + { + Console.Error.WriteLine( + $"PlayerConnect returned false"); + Environment.Exit(1); + } + } + + { + var ok = await alpha.IsPlayerConnectedAsync(playerId); + if (!ok) + { + Console.Error.WriteLine( + $"IsPlayerConnected returned false"); + Environment.Exit(1); + } + } + + { + var players = await alpha.GetConnectedPlayersAsync(); + if (players.Count == 0) + { + Console.Error.WriteLine( + $"No connected players returned"); + Environment.Exit(1); + } + } + + { + var ok = await alpha.PlayerDisconnectAsync(playerId); + if (!ok) + { + Console.Error.WriteLine( + $"PlayerDisconnect returned false"); + Environment.Exit(1); + } + } + + { + var c = await alpha.GetPlayerCountAsync(); + if (c != 0) + { + Console.Error.WriteLine( + $"Player Count should be 0, but is {c}"); + Environment.Exit(1); + } + } +} + +var shutDownStatus = await sdk.ShutDownAsync(); +if (shutDownStatus.StatusCode != StatusCode.OK) +{ + Console.Error.WriteLine( + $"Could not shutdown GameServer. StatusCode={shutDownStatus.StatusCode}, Detail={shutDownStatus.Detail}"); + Environment.Exit(1); +} \ No newline at end of file diff --git a/test/sdk/csharp/csharp.csproj b/test/sdk/csharp/csharp.csproj new file mode 100644 index 0000000000..a1f6a368a4 --- /dev/null +++ b/test/sdk/csharp/csharp.csproj @@ -0,0 +1,13 @@ + + + + Exe + net7.0 + enable + enable + + + + + + From a074e0ee89c661e75a853712408a85f8aac12cba Mon Sep 17 00:00:00 2001 From: yoshd Date: Thu, 21 Sep 2023 22:37:30 +0900 Subject: [PATCH 2/9] add successful log --- test/sdk/csharp/Program.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/sdk/csharp/Program.cs b/test/sdk/csharp/Program.cs index fc97934645..1a5dc0cb95 100644 --- a/test/sdk/csharp/Program.cs +++ b/test/sdk/csharp/Program.cs @@ -162,4 +162,6 @@ Console.Error.WriteLine( $"Could not shutdown GameServer. StatusCode={shutDownStatus.StatusCode}, Detail={shutDownStatus.Detail}"); Environment.Exit(1); -} \ No newline at end of file +} + +Console.WriteLine("All successful"); \ No newline at end of file From ff7e37ede87a0fc05b83d0e873501157a63b0823 Mon Sep 17 00:00:00 2001 From: yoshd Date: Thu, 21 Sep 2023 23:27:10 +0900 Subject: [PATCH 3/9] Fix SetLabel/SetAnnotation tests --- test/sdk/csharp/Program.cs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/test/sdk/csharp/Program.cs b/test/sdk/csharp/Program.cs index 1a5dc0cb95..cf25dbc662 100644 --- a/test/sdk/csharp/Program.cs +++ b/test/sdk/csharp/Program.cs @@ -56,25 +56,24 @@ var gameServer = await sdk.GetGameServerAsync(); Console.WriteLine("Successfully GameServer"); Console.WriteLine(gameServer); -} - -{ - var status = await sdk.SetLabelAsync("labelKey1", "labelValue1"); - if (status.StatusCode != StatusCode.OK) { - Console.Error.WriteLine( - $"Could not set label. StatusCode={status.StatusCode}, Detail={status.Detail}"); - Environment.Exit(1); + var status = await sdk.SetLabelAsync("creationTimestamp", + TimeSpan.FromSeconds(gameServer.ObjectMeta.CreationTimestamp).ToString()); + if (status.StatusCode != StatusCode.OK) + { + Console.Error.WriteLine( + $"Could not set label. StatusCode={status.StatusCode}, Detail={status.Detail}"); + Environment.Exit(1); + } } -} - -{ - var status = await sdk.SetAnnotationAsync("annotationKey1", "annotationValue1"); - if (status.StatusCode != StatusCode.OK) { - Console.Error.WriteLine( - $"Could not set annotation. StatusCode={status.StatusCode}, Detail={status.Detail}"); - Environment.Exit(1); + var status = await sdk.SetAnnotationAsync("UID", gameServer.ObjectMeta.Uid); + if (status.StatusCode != StatusCode.OK) + { + Console.Error.WriteLine( + $"Could not set annotation. StatusCode={status.StatusCode}, Detail={status.Detail}"); + Environment.Exit(1); + } } } From 685a5dfbff54df8c318e658413a81db4dc9d7b8a Mon Sep 17 00:00:00 2001 From: yoshd Date: Thu, 21 Sep 2023 23:29:19 +0900 Subject: [PATCH 4/9] Remove garbage --- test/sdk/csharp/Program.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/sdk/csharp/Program.cs b/test/sdk/csharp/Program.cs index cf25dbc662..00064ec7c9 100644 --- a/test/sdk/csharp/Program.cs +++ b/test/sdk/csharp/Program.cs @@ -1,8 +1,6 @@ using Agones; using Grpc.Core; -Console.WriteLine("Hello, World!"); - using var sdk = new AgonesSDK(); { sdk.WatchGameServer((gameServer) => From 513cf29e6ff00e83002e775a6ee9c4de89b496fa Mon Sep 17 00:00:00 2001 From: yoshd Date: Thu, 21 Sep 2023 23:38:55 +0900 Subject: [PATCH 5/9] Rename sdk test file --- build/build-sdk-images/csharp/{build-sdk-test.sh => sdktest.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename build/build-sdk-images/csharp/{build-sdk-test.sh => sdktest.sh} (100%) diff --git a/build/build-sdk-images/csharp/build-sdk-test.sh b/build/build-sdk-images/csharp/sdktest.sh similarity index 100% rename from build/build-sdk-images/csharp/build-sdk-test.sh rename to build/build-sdk-images/csharp/sdktest.sh From efb936f94e522663cfc301740e736b93a31fb109 Mon Sep 17 00:00:00 2001 From: yoshd Date: Thu, 21 Sep 2023 23:56:45 +0900 Subject: [PATCH 6/9] Fix SetLabel test --- test/sdk/csharp/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sdk/csharp/Program.cs b/test/sdk/csharp/Program.cs index 00064ec7c9..b8aa5623b3 100644 --- a/test/sdk/csharp/Program.cs +++ b/test/sdk/csharp/Program.cs @@ -56,7 +56,7 @@ Console.WriteLine(gameServer); { var status = await sdk.SetLabelAsync("creationTimestamp", - TimeSpan.FromSeconds(gameServer.ObjectMeta.CreationTimestamp).ToString()); + gameServer.ObjectMeta.CreationTimestamp.ToString()); if (status.StatusCode != StatusCode.OK) { Console.Error.WriteLine( @@ -161,4 +161,4 @@ Environment.Exit(1); } -Console.WriteLine("All successful"); \ No newline at end of file +Console.WriteLine("Finish all tests"); \ No newline at end of file From f645e0cc40141f4ccdf2828b63fba167385d3e12 Mon Sep 17 00:00:00 2001 From: yoshd Date: Fri, 22 Sep 2023 02:19:50 +0900 Subject: [PATCH 7/9] Remove unnecessary --- build/includes/sdk.mk | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build/includes/sdk.mk b/build/includes/sdk.mk index 80e482d523..c69aab8702 100644 --- a/build/includes/sdk.mk +++ b/build/includes/sdk.mk @@ -183,12 +183,8 @@ run-sdk-conformance-test-rust: run-sdk-conformance-test-csharp: # run without feature flags $(MAKE) run-sdk-conformance-test SDK_FOLDER=csharp GRPC_PORT=9005 HTTP_PORT=9105 - # run without feature flags and with RUN_ASYNC=true - DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS) -e RUN_ASYNC=true" $(MAKE) run-sdk-conformance-test SDK_FOLDER=csharp GRPC_PORT=9005 HTTP_PORT=9105 # run with feature flags enabled $(MAKE) run-sdk-conformance-test SDK_FOLDER=csharp GRPC_PORT=9005 HTTP_PORT=9105 FEATURE_GATES=PlayerTracking=true TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(ALPHA_CONFORMANCE_TESTS) - # run with feature flags enabled and with RUN_ASYNC=true - DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS) -e RUN_ASYNC=true" $(MAKE) run-sdk-conformance-test SDK_FOLDER=csharp GRPC_PORT=9005 HTTP_PORT=9105 FEATURE_GATES=PlayerTracking=true TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(ALPHA_CONFORMANCE_TESTS) run-sdk-conformance-test-rest: # (note: the restapi folder doesn't use GRPC_PORT but run-sdk-conformance-no-build defaults it, so we supply a unique value here) From 2dfe70a8d35692481a52ae627bfea804e8ce86a1 Mon Sep 17 00:00:00 2001 From: yoshd Date: Fri, 22 Sep 2023 02:24:30 +0900 Subject: [PATCH 8/9] Add Apache licence --- test/sdk/csharp/Program.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/sdk/csharp/Program.cs b/test/sdk/csharp/Program.cs index b8aa5623b3..33ab6e0c18 100644 --- a/test/sdk/csharp/Program.cs +++ b/test/sdk/csharp/Program.cs @@ -1,4 +1,17 @@ -using Agones; +// Copyright 2023 Google LLC All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using Agones; using Grpc.Core; using var sdk = new AgonesSDK(); From 72ff6217a6b8dde5b041fb1d8843fd04bd7491ca Mon Sep 17 00:00:00 2001 From: yoshd Date: Fri, 22 Sep 2023 02:57:56 +0900 Subject: [PATCH 9/9] Fixed to also install dotnet-sdk-3.1 --- build/build-sdk-images/csharp/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build-sdk-images/csharp/Dockerfile b/build/build-sdk-images/csharp/Dockerfile index ac22c4c7d9..b14a027392 100644 --- a/build/build-sdk-images/csharp/Dockerfile +++ b/build/build-sdk-images/csharp/Dockerfile @@ -31,7 +31,7 @@ RUN wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsof RUN apt-get update \ - && apt-get install -y dotnet-sdk-7.0 + && apt-get install -y dotnet-sdk-7.0 dotnet-sdk-3.1 # code generation scripts COPY *.sh /root/