Files
UnrealEngineUWP/Engine/Source/Programs/Horde/HordeServerTests/AgentServiceTest.cs
Ben Marsh a43fa8aa30 Horde: Fix tests.
[CL 16561732 by Ben Marsh in ue5-main branch]
2021-06-04 16:01:32 -04:00

72 lines
2.6 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using HordeCommon;
using HordeServer.Api;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HordeServer.Models;
using HordeServer.Services;
using Microsoft.AspNetCore.Mvc;
using AgentSoftwareVersion = HordeServer.Utilities.StringId<HordeServer.Collections.IAgentSoftwareCollection>;
using HordeServer.Utilities;
using MongoDB.Bson;
namespace HordeServerTests
{
/// <summary>
/// Testing the agent service
/// </summary>
[TestClass]
public class AgentServiceTest : DatabaseIntegrationTest
{
[TestMethod]
public async Task GetJobs()
{
TestSetup TestSetup = await GetTestSetup();
ActionResult<List<object>> Res = await TestSetup.JobsController.FindJobsAsync();
Assert.AreEqual(2, Res.Value.Count);
Assert.AreEqual("hello2", (Res.Value[0] as GetJobResponse)!.Name);
Assert.AreEqual("hello1", (Res.Value[1] as GetJobResponse)!.Name);
Res = await TestSetup.JobsController.FindJobsAsync(IncludePreflight: false);
Assert.AreEqual(1, Res.Value.Count);
Assert.AreEqual("hello2", (Res.Value[0] as GetJobResponse)!.Name);
}
[TestMethod]
public async Task CreateSessionTest()
{
TestSetup TestSetup = await GetTestSetup();
AgentService AgentService = TestSetup.AgentService;
IAgent Agent = await AgentService.CreateSessionAsync(TestSetup.Fixture!.Agent1, AgentStatus.Ok, new AgentCapabilities(),
"test");
Assert.IsTrue(AgentService.AuthorizeSession(Agent, GetUser(Agent)));
TestSetup.Clock.Advance(TimeSpan.FromMinutes(20));
Assert.IsFalse(AgentService.AuthorizeSession(Agent, GetUser(Agent)));
}
[TestMethod]
public async Task AgentListenerDispose()
{
// Test created to verify dispose bug with AgentEventListener
TestSetup TestSetup = await GetTestSetup();
AgentService AgentService = TestSetup.AgentService;
AgentService.AgentEventListener Listener = new AgentService.AgentEventListener(AgentService, new AgentId("test"), ObjectId.GenerateNewId(), () => { });
Listener.Dispose();
}
private ClaimsPrincipal GetUser(IAgent Agent)
{
return new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
{
new Claim(HordeClaimTypes.AgentSessionId, Agent.SessionId.ToString()),
}, "TestAuthType"));
}
}
}