Skip to content

Commit

Permalink
Merge pull request #154 from Lombiq/issue/OSOE-101
Browse files Browse the repository at this point in the history
OSOE-101: Fixing snapshot handling
  • Loading branch information
Piedone authored Apr 14, 2022
2 parents d4de690 + ce06581 commit 5b57f73
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
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

0 comments on commit 5b57f73

Please sign in to comment.