diff --git a/Lombiq.Tests.UI/Services/OrchardCoreSetupConfiguration.cs b/Lombiq.Tests.UI/Services/OrchardCoreSetupConfiguration.cs index f90a28164..4da7a0bfb 100644 --- a/Lombiq.Tests.UI/Services/OrchardCoreSetupConfiguration.cs +++ b/Lombiq.Tests.UI/Services/OrchardCoreSetupConfiguration.cs @@ -1,5 +1,6 @@ using Lombiq.Tests.UI.Constants; using System; +using System.IO; using System.Threading.Tasks; namespace Lombiq.Tests.UI.Services; @@ -30,7 +31,8 @@ public class OrchardCoreSetupConfiguration /// 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; } } diff --git a/Lombiq.Tests.UI/Services/UITestExecutionSession.cs b/Lombiq.Tests.UI/Services/UITestExecutionSession.cs index 4f81b4bc9..28e1679f8 100644 --- a/Lombiq.Tests.UI/Services/UITestExecutionSession.cs +++ b/Lombiq.Tests.UI/Services/UITestExecutionSession.cs @@ -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; @@ -65,24 +66,26 @@ public async Task 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( @@ -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); @@ -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); }