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

OSOE-402: Adapting to UI testing logging changes #132

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
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 .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ on:
jobs:
publish-nuget:
name: Publish to NuGet
uses: Lombiq/GitHub-Actions/.github/workflows/publish-nuget.yml@dev
uses: Lombiq/GitHub-Actions/.github/workflows/publish-nuget.yml@issue/OSOE-402
secrets:
API_KEY: ${{ secrets.DEFAULT_NUGET_PUBLISH_API_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/validate-nuget-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ on:
jobs:
validate-nuget-publish:
name: Validate NuGet Publish
uses: Lombiq/GitHub-Actions/.github/workflows/validate-nuget-publish.yml@dev
uses: Lombiq/GitHub-Actions/.github/workflows/validate-nuget-publish.yml@issue/OSOE-402
dministro marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.Extensions.IdleTenantManagementExtensions.AssertAppLogsWithIdleCheckAsync(Lombiq.Tests.UI.Services.IWebApplicationInstance)</Target>
<Left>lib/net8.0/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.dll</Left>
<Right>lib/net8.0/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.Extensions.IdleTenantManagementExtensions.SetMaxIdleMinutesAndLoggingForUITest(Lombiq.Tests.UI.Services.OrchardCoreUITestExecutorConfiguration)</Target>
<Left>lib/net8.0/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.dll</Left>
<Right>lib/net8.0/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
</Suppressions>
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Helpers;
using Lombiq.Tests.UI.Services;
using Shouldly;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using static Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.Constants.IdleTenantData;

namespace Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.Extensions;

public static class IdleTenantManagementExtensions
{
public static void SetMaxIdleMinutesAndLoggingForUITest(this OrchardCoreUITestExecutorConfiguration configuration) =>
public static void ConfigureIdleTenantManagementTestSettings(this OrchardCoreUITestExecutorConfiguration configuration)
{
configuration.OrchardCoreConfiguration.BeforeAppStart +=
(_, argumentsBuilder) =>
{
argumentsBuilder
.AddWithValue(
"OrchardCore:Lombiq_Hosting_Tenants_IdleTenantManagement:IdleShutdownOptions:MaxIdleMinutes",
"1");

argumentsBuilder
.AddWithValue("Logging:LogLevel:Default", "Information");
"1")
.AddWithValue(
"Logging:LogLevel:Lombiq.Hosting.Tenants.IdleTenantManagement.Services.IdleShutdownService",
"Information");

return Task.CompletedTask;
};

public static async Task AssertAppLogsWithIdleCheckAsync(this IWebApplicationInstance webApplicationInstance) =>
(await webApplicationInstance.GetLogOutputAsync())
.ShouldContain($"Shutting down tenant \"{IdleTenantName}\" because of idle timeout.");
configuration.OrchardCoreConfiguration.AfterFakeLoggingConfiguration =
(_, fakeLogCollectorOptions) => fakeLogCollectorOptions.FilteredLevels.Add(LogLevel.Information);

configuration.AssertAppLogsAsync = app =>
app.LogsShouldNotContainAsync(logEntry =>
AppLogAssertionHelper.NotMediaCacheEntries(logEntry) && logEntry.Level != LogLevel.Information);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ await context.GoToSetupPageAndSetupOrchardCoreAsync(
RunSetupOnCurrentPage = true,
});

await context.SignInDirectlyAsync();

// We are letting the site to sit idle for more than two minutes so that the tenant could be shut down by the
// We are letting the site to sit idle for more than two minutes so that the tenant can be shut down by the
// background task.
await Task.Delay(129420);

Expand All @@ -38,6 +36,7 @@ await context.GoToSetupPageAndSetupOrchardCoreAsync(
await context.GoToDashboardAsync();

// Make sure the shutdown message is in the logs.
await context.Application.AssertAppLogsWithIdleCheckAsync();
await context.Application.LogsShouldContainAsync(logEntry =>
logEntry.Message == $"Shutting down tenant \"{IdleTenantName}\" because of idle timeout.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.Tests.UI" Version="11.0.0" />
<PackageReference Include="Lombiq.Tests.UI" Version="11.1.1-alpha.0.osoe-402" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Lombiq.Hosting.Tenants.IdleTenantManagement.Services.IdleShutdown</Target>
<Left>lib/net8.0/Lombiq.Hosting.Tenants.IdleTenantManagement.dll</Left>
<Right>lib/net8.0/Lombiq.Hosting.Tenants.IdleTenantManagement.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Lombiq.Hosting.Tenants.IdleTenantManagement.Services.IIdleShutdown</Target>
<Left>lib/net8.0/Lombiq.Hosting.Tenants.IdleTenantManagement.dll</Left>
<Right>lib/net8.0/Lombiq.Hosting.Tenants.IdleTenantManagement.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
</Suppressions>
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Threading.Tasks;
using System.Threading.Tasks;

namespace Lombiq.Hosting.Tenants.IdleTenantManagement.Services;

/// <summary>
/// Service to shut down idle tenants.
/// </summary>
public interface IIdleShutdown
internal interface IIdleShutdownService
{
/// <summary>
/// Shuts down idle tenants if they are idle for more than the configured time.
/// </summary>
Task ShutDownIdleTenantsAsync();
Task ShutDownTenantIfIdleAsync();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lombiq.Hosting.Tenants.IdleTenantManagement.Models;
using Lombiq.Hosting.Tenants.IdleTenantManagement.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OrchardCore.Environment.Shell;
Expand All @@ -7,21 +7,21 @@

namespace Lombiq.Hosting.Tenants.IdleTenantManagement.Services;

public class IdleShutdown : IIdleShutdown
internal sealed class IdleShutdownService : IIdleShutdownService
{
private readonly IOptions<IdleShutdownOptions> _options;
private readonly ShellSettings _shellSettings;
private readonly IClock _clock;
private readonly ILastActiveTimeAccessor _lastActiveTimeAccessor;
private readonly ILogger<IdleShutdown> _logger;
private readonly ILogger<IdleShutdownService> _logger;
private readonly IShellHost _shellHost;

public IdleShutdown(
public IdleShutdownService(
IOptions<IdleShutdownOptions> options,
ShellSettings shellSettings,
IClock clock,
ILastActiveTimeAccessor lastActiveTimeAccessor,
ILogger<IdleShutdown> logger,
ILogger<IdleShutdownService> logger,
IShellHost shellHost)
{
_options = options;
Expand All @@ -32,7 +32,7 @@ public IdleShutdown(
_shellHost = shellHost;
}

public async Task ShutDownIdleTenantsAsync()
public async Task ShutDownTenantIfIdleAsync()
{
var maxIdleMinutes = _options.Value.MaxIdleMinutes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public sealed class IdleShutdownTask : IBackgroundTask
{
public Task DoWorkAsync(IServiceProvider serviceProvider, CancellationToken cancellationToken)
{
var idleShutdown = serviceProvider.GetRequiredService<IIdleShutdown>();
var idleShutdownService = serviceProvider.GetRequiredService<IIdleShutdownService>();

return idleShutdown.ShutDownIdleTenantsAsync();
return idleShutdownService.ShutDownTenantIfIdleAsync();
}
}
2 changes: 1 addition & 1 deletion Lombiq.Hosting.Tenants.IdleTenantManagement/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void Configure(
public override void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<ILastActiveTimeAccessor, LastActiveTimeAccessor>();
services.AddScoped<IIdleShutdown, IdleShutdown>();
services.AddScoped<IIdleShutdownService, IdleShutdownService>();
services.AddSingleton<IBackgroundTask, IdleShutdownTask>();

// Idle Minutes Settings
Expand Down
Loading