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

Add conformance test implementation for C# SDK #3392

Merged
merged 11 commits into from
Sep 22, 2023
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
2 changes: 1 addition & 1 deletion build/build-sdk-images/csharp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 dotnet-sdk-3.1

# code generation scripts
COPY *.sh /root/
Expand Down
21 changes: 21 additions & 0 deletions build/build-sdk-images/csharp/sdktest.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion build/includes/sdk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ 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 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-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
Expand All @@ -190,7 +196,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
Expand Down
177 changes: 177 additions & 0 deletions test/sdk/csharp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
// 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();
{
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("creationTimestamp",
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("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);
}
}
}

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);
}

Console.WriteLine("Finish all tests");
13 changes: 13 additions & 0 deletions test/sdk/csharp/csharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../../sdks/csharp/sdk/csharp-sdk.csproj" />
</ItemGroup>
</Project>