Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update integration tests (#512)
Leendert de Borstfafa51d7878d
diff --git a/src/Tests/AliasVault.IntegrationTests/AbstractTestHostBuilder.cs b/src/Tests/AliasVault.IntegrationTests/AbstractTestHostBuilder.csindex 7d88f0909..5d468f5b5 100644--- a/src/Tests/AliasVault.IntegrationTests/AbstractTestHostBuilder.cs+++ b/src/Tests/AliasVault.IntegrationTests/AbstractTestHostBuilder.cs@@ -7,8 +7,10 @@namespace AliasVault.IntegrationTests;+using System.Reflection;using AliasServerDb;using AliasServerDb.Configuration;+using AliasVault.Logging;using Microsoft.EntityFrameworkCore;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;@@ -145,6 +147,7 @@ public class AbstractTestHostBuilder : IAsyncDisposableservices.AddSingleton<IConfiguration>(configuration);services.AddAliasVaultDatabaseConfiguration(configuration);+ services.ConfigureLogging(configuration, Assembly.GetExecutingAssembly().GetName().Name!, "logs");// Ensure the in-memory database is populated with tablesvar serviceProvider = services.BuildServiceProvider();diff --git a/src/Tests/AliasVault.IntegrationTests/StatusHostedService/StatusHostedServiceTests.cs b/src/Tests/AliasVault.IntegrationTests/StatusHostedService/StatusHostedServiceTests.csindex c03fd43f4..6bee038cc 100644--- a/src/Tests/AliasVault.IntegrationTests/StatusHostedService/StatusHostedServiceTests.cs+++ b/src/Tests/AliasVault.IntegrationTests/StatusHostedService/StatusHostedServiceTests.cs@@ -55,13 +55,13 @@ public class StatusHostedServiceTests[Test]public async Task LogsExceptionFromWrappedService(){- // Start the service which will trigger the TestExceptionWorker to throw+ // Start the service which will trigger the TestExceptionWorker to throw an exception.await _testHost.StartAsync();- // Give it a moment to process- await Task.Delay(5000);+ // Give it a moment to process.+ await Task.Delay(3000);- // Check the logs for the expected error+ // Check the logs for the expected error.await using var dbContext = _testHostBuilder.GetDbContext();var errorLog = await dbContext.Logs.OrderByDescending(l => l.TimeStamp)diff --git a/src/Tests/AliasVault.IntegrationTests/StatusHostedService/TestHostBuilder.cs b/src/Tests/AliasVault.IntegrationTests/StatusHostedService/TestHostBuilder.csindex b0200b0df..a0874c251 100644--- a/src/Tests/AliasVault.IntegrationTests/StatusHostedService/TestHostBuilder.cs+++ b/src/Tests/AliasVault.IntegrationTests/StatusHostedService/TestHostBuilder.cs@@ -4,19 +4,12 @@// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.// </copyright>// ------------------------------------------------------------------------namespace AliasVault.IntegrationTests.StatusHostedService;-using System.Data.Common;using System.Reflection;using AliasServerDb;-using AliasServerDb.Configuration;using AliasVault.WorkerStatus.ServiceExtensions;-using Microsoft.EntityFrameworkCore;-using Microsoft.Extensions.Configuration;-using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;-using Npgsql;/// <summary>/// Builder class for creating a test host for the StatusHostedService wrapper in order to run integration testsdiff --git a/src/Tests/AliasVault.IntegrationTests/TaskRunner/TaskRunnerTests.cs b/src/Tests/AliasVault.IntegrationTests/TaskRunner/TaskRunnerTests.csindex d703dd769..54dd8db89 100644--- a/src/Tests/AliasVault.IntegrationTests/TaskRunner/TaskRunnerTests.cs+++ b/src/Tests/AliasVault.IntegrationTests/TaskRunner/TaskRunnerTests.cs@@ -77,7 +77,7 @@ public class TaskRunnerTests// Assertawait using var dbContext = await _testHostBuilder.GetDbContextAsync();- var generalLogs = await dbContext.Logs.ToListAsync();+ var generalLogs = await dbContext.Logs.Where(x => x.Application == "TestApp").ToListAsync();Assert.That(generalLogs, Has.Count.EqualTo(50), "Only recent general logs should remain");}diff --git a/src/Utilities/AliasVault.WorkerStatus/ServiceExtensions/StatusHostedService.cs b/src/Utilities/AliasVault.WorkerStatus/ServiceExtensions/StatusHostedService.csindex 6b9b8213b..6d70f0c32 100644--- a/src/Utilities/AliasVault.WorkerStatus/ServiceExtensions/StatusHostedService.cs+++ b/src/Utilities/AliasVault.WorkerStatus/ServiceExtensions/StatusHostedService.cs@@ -27,7 +27,7 @@ public class StatusHostedService<T>(ILogger<StatusHostedService<T>> logger, Glob/// <summary>/// Maximum delay before restarting the worker./// </summary>- private const int _restartMaxDelayInMs = 300000;+ private const int _restartMaxDelayInMs = 3600000;/// <summary>/// Lock object to prevent multiple tasks from starting the worker at the same time.@@ -120,9 +120,23 @@ public class StatusHostedService<T>(ILogger<StatusHostedService<T>> logger, Glob{globalServiceStatus.SetWorkerStatus(typeof(T).Name, true);- await innerService.StartAsync(cancellationToken);+ // If the inner service is a BackgroundService, listen for the results via reflection.+ if (innerService is BackgroundService backgroundService)+ {+ var executeMethod = backgroundService.GetType().GetMethod("ExecuteAsync", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);+ var executionTask = (Task)executeMethod!.Invoke(backgroundService, new object[] { cancellationToken })!;++ // Wait for the ExecuteAsync method to complete or throw.+ await executionTask;+ }+ else+ {+ // For non-BackgroundService implementations, start the service as normal and wait indefinitely+ await innerService.StartAsync(cancellationToken);- await Task.Delay(Timeout.Infinite, cancellationToken);+ // For non-BackgroundService implementations, just wait indefinitely+ await Task.Delay(Timeout.Infinite, cancellationToken);+ }}catch (OperationCanceledException ex){@@ -132,6 +146,7 @@ public class StatusHostedService<T>(ILogger<StatusHostedService<T>> logger, Globcatch (Exception ex){logger.LogError(ex, "An error occurred in StatusHostedService<{ServiceType}>", typeof(T).Name);+ globalServiceStatus.SetWorkerStatus(typeof(T).Name, false);}finally{@@ -139,7 +154,7 @@ public class StatusHostedService<T>(ILogger<StatusHostedService<T>> logger, GlobglobalServiceStatus.SetWorkerStatus(typeof(T).Name, false);}- // If a fault occurred in the innerService but it was not canceled,+ // If a fault occurred in the innerService, but it was not explicitly canceled,// wait for a second before attempting to auto-restart the worker.while (!cancellationToken.IsCancellationRequested){