Skip to content

Commit

Permalink
Use postgreSQL for mission eventh handler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aeshub committed Jan 21, 2025
1 parent ab69746 commit a7360a0
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions backend/api.test/EventHandlers/TestMissionEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Moq;
using Testcontainers.PostgreSql;
using Xunit;

namespace Api.Test.EventHandlers
Expand All @@ -24,6 +25,7 @@ public class TestMissionEventHandler : IAsyncLifetime, IAsyncDisposable
public required TestWebApplicationFactory<Program> Factory;
public required IServiceProvider ServiceProvider;

public required PostgreSqlContainer Container;
public required string ConnectionString;

public required DatabaseUtilities DatabaseUtilities;
Expand All @@ -36,14 +38,15 @@ public class TestMissionEventHandler : IAsyncLifetime, IAsyncDisposable

public async Task InitializeAsync()
{
string databaseName = Guid.NewGuid().ToString();
(ConnectionString, _) = await TestSetupHelpers.ConfigureSqLiteDatabase(databaseName);

DatabaseUtilities = new DatabaseUtilities(Context);
(Container, ConnectionString, var connection) =
await TestSetupHelpers.ConfigurePostgreSqlDatabase();
Factory = TestSetupHelpers.ConfigureWebApplicationFactory(
postgreSqlConnectionString: ConnectionString
);

Factory = TestSetupHelpers.ConfigureWebApplicationFactory(databaseName);
ServiceProvider = TestSetupHelpers.ConfigureServiceProvider(Factory);

DatabaseUtilities = new DatabaseUtilities(Context);
MissionRunService = ServiceProvider.GetRequiredService<IMissionRunService>();
RobotService = ServiceProvider.GetRequiredService<IRobotService>();
MissionSchedulingService =
Expand All @@ -55,8 +58,7 @@ public async Task InitializeAsync()

public async Task DisposeAsync()
{
await Context.Database.EnsureDeletedAsync();
await Context.Database.EnsureCreatedAsync();
await Task.CompletedTask;
}

async ValueTask IAsyncDisposable.DisposeAsync()
Expand All @@ -66,7 +68,7 @@ async ValueTask IAsyncDisposable.DisposeAsync()

private FlotillaDbContext CreateContext()
{
return TestSetupHelpers.ConfigureSqLiteContext(ConnectionString);
return TestSetupHelpers.ConfigurePostgreSqlContext(ConnectionString);
}

[Fact]
Expand Down Expand Up @@ -270,7 +272,7 @@ public async Task MissionRunIsStartedForOtherAvailableRobotIfOneRobotHasAnOngoin

// Act (Ensure first mission is started)
await MissionRunService.Create(missionRunOne);
Thread.Sleep(100);
Thread.Sleep(1000);

// Assert
var postStartMissionRunOne = await MissionRunService.ReadById(
Expand All @@ -282,7 +284,7 @@ public async Task MissionRunIsStartedForOtherAvailableRobotIfOneRobotHasAnOngoin

// Act (Ensure second mission is started for second robot)
await MissionRunService.Create(missionRunTwo);
Thread.Sleep(100);
Thread.Sleep(1000);

// Assert
var postStartMissionRunTwo = await MissionRunService.ReadById(
Expand Down Expand Up @@ -353,6 +355,8 @@ public async Task QueuedMissionsAreNotAbortedWhenRobotAvailableHappensAtTheSameT
robotAvailableEventArgs
);

Thread.Sleep(100);

// Assert
var postTestMissionRunOne = await MissionRunService.ReadById(
missionRunOne.Id,
Expand Down

0 comments on commit a7360a0

Please sign in to comment.