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-101: Fixing snapshot handling #154

Merged
merged 9 commits into from
Apr 14, 2022
4 changes: 3 additions & 1 deletion Lombiq.Tests.UI/Services/OrchardCoreSetupConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Lombiq.Tests.UI.Constants;
using System;
using System.IO;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.Services;
Expand Down Expand Up @@ -30,7 +31,8 @@ public class OrchardCoreSetupConfiguration
/// </summary>
public bool FastFailSetup { get; set; } = true;

public string SetupSnapshotDirectoryPath { get; set; } = DirectoryPaths.SetupSnapshot;
public string SetupSnapshotDirectoryPath { get; set; } =
Path.Combine(DirectoryPaths.Temp, DirectoryPaths.SetupSnapshot);

public BeforeSetupHandler BeforeSetup { get; set; }
}
38 changes: 22 additions & 16 deletions Lombiq.Tests.UI/Services/UITestExecutionSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal sealed class UITestExecutionSession : IAsyncDisposable

private SynchronizingWebApplicationSnapshotManager _currentSetupSnapshotManager;
private string _snapshotDirectoryPath;
private bool _hasSetupOperation;
private SqlServerManager _sqlServerManager;
private SmtpService _smtpService;
private AzureBlobStorageManager _azureBlobStorageManager;
Expand All @@ -65,24 +66,26 @@ public async Task<bool> ExecuteAsync(int retryCount, string dumpRootPath)
try
{
var setupConfiguration = _configuration.SetupConfiguration;
var hasSetupOperation = setupConfiguration.SetupOperation != null;
_hasSetupOperation = setupConfiguration.SetupOperation != null;

var snapshotSubdirectory = "Default";
if (_configuration.UseSqlServer)
if (_hasSetupOperation)
{
snapshotSubdirectory = _configuration.UseAzureBlobStorage
? "SqlServer-AzureBlob"
: "SqlServer";
}
else if (_configuration.UseAzureBlobStorage)
{
snapshotSubdirectory = "AzureBlob";
}
var snapshotSubdirectory = "Default";
if (_configuration.UseSqlServer)
{
snapshotSubdirectory = _configuration.UseAzureBlobStorage
? "SqlServer-AzureBlob"
: "SqlServer";
}
else if (_configuration.UseAzureBlobStorage)
{
snapshotSubdirectory = "AzureBlob";
}

_snapshotDirectoryPath = Path.Combine(setupConfiguration.SetupSnapshotDirectoryPath, snapshotSubdirectory);
snapshotSubdirectory += "-" + setupConfiguration.SetupOperation.GetHashCode().ToTechnicalString();

_snapshotDirectoryPath = Path.Combine(setupConfiguration.SetupSnapshotDirectoryPath, snapshotSubdirectory);

if (hasSetupOperation)
{
_configuration.OrchardCoreConfiguration.SnapshotDirectoryPath = _snapshotDirectoryPath;

_currentSetupSnapshotManager = _setupSnapshotManagers.GetOrAdd(
Expand Down Expand Up @@ -622,7 +625,10 @@ async Task SqlServerManagerBeforeAppStartHandlerAsync(string contentRootPath, Ar
_dockerConfiguration?.ContainerSnapshotPath ??
_snapshotDirectoryPath;

if (!Directory.Exists(_dockerConfiguration?.HostSnapshotPath ?? snapshotDirectoryPath)) return;
if (!_hasSetupOperation || !Directory.Exists(_dockerConfiguration?.HostSnapshotPath ?? snapshotDirectoryPath))
{
return;
}

_sqlServerManager.RestoreSnapshot(snapshotDirectoryPath);

Expand Down Expand Up @@ -669,7 +675,7 @@ async Task AzureBlobStorageManagerBeforeAppStartHandlerAsync(string contentRootP
argumentsBuilder.Add("--OrchardCore:OrchardCore_Media_Azure:CreateContainer").Add("true");
argumentsBuilder.Add("--Lombiq_Tests_UI:UseAzureBlobStorage").Add("true");

if (!Directory.Exists(_snapshotDirectoryPath)) return;
if (!_hasSetupOperation || !Directory.Exists(_snapshotDirectoryPath)) return;

await _azureBlobStorageManager.RestoreSnapshotAsync(_snapshotDirectoryPath);
}
Expand Down