Skip to content

Commit

Permalink
Add integration tests for /health and /metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Feb 17, 2025
1 parent 8fab998 commit 869092f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/Tgstation.Server.Tests/Live/LiveTestingServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public LiveTestingServer(SwarmConfiguration swarmConfiguration, bool enableOAuth
$"Security:TokenExpiryMinutes=120", // timeouts are useless for us
$"General:OpenDreamSuppressInstallOutput={TestingUtils.RunningInGitHubActions}",
"Telemetry:DisableVersionReporting=true",
$"General:PrometheusPort={port}"
};

if (MultiServerClient.UseGraphQL)
Expand Down
38 changes: 37 additions & 1 deletion tests/Tgstation.Server.Tests/Live/RawRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,40 @@ await serverClient.Users.Update(new UserUpdateRequest
}
}

static async Task TestHealthChecks(IRestServerClient serverClient, CancellationToken cancellationToken)
{
var url = serverClient.Url;
// check that 400s are returned appropriately
using var httpClient = new HttpClient();
using (var request = new HttpRequestMessage(HttpMethod.Get, url.ToString() + "health"))
{
request.Headers.Accept.Clear();
request.Headers.UserAgent.Add(new ProductInfoHeaderValue("RootTest", "1.0.0"));
using var response = await httpClient.SendAsync(request, cancellationToken);
response.EnsureSuccessStatusCode();

var text = await response.Content.ReadAsStringAsync(cancellationToken);
Assert.AreEqual("Healthy", text.Trim());
}
}

static async Task TestPrometheusMetrics(IRestServerClient serverClient, CancellationToken cancellationToken)
{
var url = serverClient.Url;
// check that 400s are returned appropriately
using var httpClient = new HttpClient();
using (var request = new HttpRequestMessage(HttpMethod.Get, url.ToString() + "metrics"))
{
request.Headers.Accept.Clear();
request.Headers.UserAgent.Add(new ProductInfoHeaderValue("RootTest", "1.0.0"));
using var response = await httpClient.SendAsync(request, cancellationToken);
response.EnsureSuccessStatusCode();

var text = await response.Content.ReadAsStringAsync(cancellationToken);
Assert.IsTrue(text.Contains("tgs_jobs_running"));
}
}

static async Task TestGraphQLLogin(IRestServerClientFactory clientFactory, IRestServerClient restClient, CancellationToken cancellationToken)
{
if (!MultiServerClient.UseGraphQL)
Expand Down Expand Up @@ -483,6 +517,8 @@ public static Task Run(IRestServerClientFactory clientFactory, IRestServerClient
TestServerInformation(clientFactory, serverClient, cancellationToken),
TestInvalidTransfers(serverClient, cancellationToken),
RegressionTestForLeakedPasswordHashesBug(serverClient, cancellationToken),
TestSignalRUsage(clientFactory, serverClient, cancellationToken));
TestSignalRUsage(clientFactory, serverClient, cancellationToken),
TestHealthChecks(serverClient, cancellationToken),
TestPrometheusMetrics(serverClient, cancellationToken));
}
}

0 comments on commit 869092f

Please sign in to comment.