diff --git a/test/MusicStore.E2ETests/MusicStore.E2ETests.csproj b/test/MusicStore.E2ETests/MusicStore.E2ETests.csproj index bfebb5507c..5b5f46ac60 100644 --- a/test/MusicStore.E2ETests/MusicStore.E2ETests.csproj +++ b/test/MusicStore.E2ETests/MusicStore.E2ETests.csproj @@ -15,10 +15,6 @@ - - - - diff --git a/test/MusicStore.E2ETests/SmokeTestsUsingStore/Store.cs b/test/MusicStore.E2ETests/SmokeTestsUsingStore/Store.cs deleted file mode 100644 index a53ad136ee..0000000000 --- a/test/MusicStore.E2ETests/SmokeTestsUsingStore/Store.cs +++ /dev/null @@ -1,195 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Server.IntegrationTesting; -using Microsoft.Extensions.DependencyModel; -using Microsoft.Extensions.Logging; - -namespace E2ETests -{ - internal class Store : IDisposable - { - private readonly ILogger _logger; - private string _storeParentDir; - private string _storeDir; - - public Store(ILoggerFactory loggerFactory) - { - _logger = loggerFactory.CreateLogger(); - } - - public string CreateStore() - { - _storeParentDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); - - InstallStore(_storeParentDir); - - _storeDir = Path.Combine(_storeParentDir, "store"); - - return _storeDir; - } - - public void Dispose() - { - if (string.IsNullOrEmpty(_storeDir)) - { - return; - } - - if (Helpers.PreservePublishedApplicationForDebugging) - { - _logger.LogInformation("Skipping deleting the store as it has been disabled"); - } - else - { - _logger.LogInformation($"Deleting the store directory {_storeParentDir}..."); - - RetryHelper.RetryOperation( - () => Directory.Delete(_storeParentDir, recursive: true), - e => _logger.LogError($"Failed to delete directory : {e.Message}"), - retryCount: 3, - retryDelayMilliseconds: 100); - } - } - - public static bool IsEnabled() - { - var storeFeed = Environment.GetEnvironmentVariable("RUN_RUNTIME_STORE_TESTS"); - return !string.IsNullOrEmpty(storeFeed); - } - - private void InstallStore(string storeParentDir) - { - var packageId = "Build.RS"; - - var runtimeStoreLibrary = DependencyContext.Default.RuntimeLibraries - .Where(library => string.Equals(packageId, library.Name, StringComparison.OrdinalIgnoreCase)) - .FirstOrDefault(); - if (runtimeStoreLibrary == null) - { - throw new InvalidOperationException($"Could not find the package with id '{packageId}' in {nameof(DependencyContext)}."); - } - - var runtimeStoreVersion = runtimeStoreLibrary.Version; - var restoredRuntimeStorePackageDir = Path.Combine(GetNugetPackagesRoot(), runtimeStoreLibrary.Path); - - _logger.LogInformation($"Location of the restored runtime store package '{packageId}': {restoredRuntimeStorePackageDir}"); - - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - string fileNameWithExtension = null; - foreach (var file in new DirectoryInfo(restoredRuntimeStorePackageDir).GetFiles()) - { - if (file.Name.StartsWith($"{packageId}.winx64")) - { - using (var zipArchive = ZipFile.Open(file.FullName, ZipArchiveMode.Read)) - { - var mvcCoreDllEntry = zipArchive.Entries - .Where(entry => string.Equals(entry.Name, "Microsoft.AspNetCore.Mvc.Core.dll", StringComparison.OrdinalIgnoreCase)) - .FirstOrDefault(); - if (mvcCoreDllEntry != null && mvcCoreDllEntry.FullName.Contains(runtimeStoreVersion)) - { - fileNameWithExtension = file.Name; - break; - } - } - } - } - - if (string.IsNullOrEmpty(fileNameWithExtension)) - { - throw new InvalidOperationException($"Could not find a store zip file with version {runtimeStoreVersion}"); - } - - var storeZipFile = Path.Combine(restoredRuntimeStorePackageDir, fileNameWithExtension); - ZipFile.ExtractToDirectory(storeZipFile, storeParentDir); - _logger.LogInformation($"Extracted the store zip file '{storeZipFile}' to '{storeParentDir}'"); - } - else - { - string packageIdPrefix; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - packageIdPrefix = $"{packageId}.linux"; - } - else - { - packageIdPrefix = $"{packageId}.osx"; - } - - string fileNameWithExtension = null; - var tarFile = $"{packageIdPrefix}.tar.gz"; - foreach (var file in new DirectoryInfo(restoredRuntimeStorePackageDir).GetFiles()) - { - if (file.Name.StartsWith(packageIdPrefix) - && !string.Equals(tarFile, file.Name, StringComparison.OrdinalIgnoreCase)) - { - fileNameWithExtension = file.FullName; - break; - } - } - - if (string.IsNullOrEmpty(fileNameWithExtension)) - { - throw new InvalidOperationException( - $"Could not find a store tar file with version {runtimeStoreVersion}"); - } - - _logger.LogInformation($"Extracting the store tar file '{fileNameWithExtension}' to '{storeParentDir}' ..."); - - Directory.CreateDirectory(storeParentDir); - - var startInfo = new ProcessStartInfo() - { - FileName = "tar", - Arguments = $"xvzf {fileNameWithExtension}", - WorkingDirectory = storeParentDir, - UseShellExecute = false, - CreateNoWindow = true, - RedirectStandardError = true, - RedirectStandardOutput = true, - RedirectStandardInput = true - }; - var tarProcess = new Process() { StartInfo = startInfo }; - tarProcess.EnableRaisingEvents = true; - tarProcess.StartAndCaptureOutAndErrToLogger("tar", _logger); - - if (tarProcess.HasExited && tarProcess.ExitCode != 0) - { - var message = $"Error occurred while extracting the file '{fileNameWithExtension}' in working directory '{storeParentDir}'"; - _logger.LogError(message); - throw new InvalidOperationException(message); - } - } - } - - private string GetNugetPackagesRoot() - { - var packageDirectory = Environment.GetEnvironmentVariable("NUGET_PACKAGES"); - if (!string.IsNullOrEmpty(packageDirectory)) - { - return packageDirectory; - } - - string basePath; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - basePath = Environment.GetEnvironmentVariable("USERPROFILE"); - } - else - { - basePath = Environment.GetEnvironmentVariable("HOME"); - } - - if (string.IsNullOrEmpty(basePath)) - { - return null; - } - - return Path.Combine(basePath, ".nuget", "packages"); - } - } -} diff --git a/test/MusicStore.E2ETests/SmokeTestsUsingStore/StoreSetupFixture.cs b/test/MusicStore.E2ETests/SmokeTestsUsingStore/StoreSetupFixture.cs deleted file mode 100644 index 3960a6265b..0000000000 --- a/test/MusicStore.E2ETests/SmokeTestsUsingStore/StoreSetupFixture.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Testing; - -namespace E2ETests -{ - public class StoreSetupFixture : IDisposable - { - private readonly IDisposable _logToken; - private readonly ILogger _logger; - private readonly Store _store; - - public StoreSetupFixture() - { - if (!Store.IsEnabled()) - { - return; - } - - var loggerName = nameof(StoreSetupFixture); - var testLog = AssemblyTestLog.ForAssembly(typeof(StoreSetupFixture).Assembly); - ILoggerFactory loggerFactory; - _logToken = testLog.StartTestLog(null, loggerName, out loggerFactory, testName: loggerName); - _logger = loggerFactory.CreateLogger(); - - _store = new Store(loggerFactory); - - StoreDirectory = _store.CreateStore(); - - _logger.LogInformation($"Store was setup at {StoreDirectory}"); - } - - public string StoreDirectory { get; } - - public void Dispose() - { - if (_store != null) - { - _store.Dispose(); - } - - if (_logToken != null) - { - _logToken.Dispose(); - } - } - } -} \ No newline at end of file diff --git a/test/MusicStore.E2ETests/SmokeTestsUsingStore/TestHelper.cs b/test/MusicStore.E2ETests/SmokeTestsUsingStore/TestHelper.cs index 1ad2667f66..ed563dd220 100644 --- a/test/MusicStore.E2ETests/SmokeTestsUsingStore/TestHelper.cs +++ b/test/MusicStore.E2ETests/SmokeTestsUsingStore/TestHelper.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; using System.IO; using System.Text; @@ -17,7 +20,7 @@ namespace E2ETests.SmokeTestsUsingStore { } - public async Task SmokeTestSuite(ServerType serverType, string storeDirectory) + public async Task SmokeTestSuite(ServerType serverType) { var targetFramework = "netcoreapp2.0"; var testName = $"SmokeTestsUsingStore_{serverType}"; @@ -48,9 +51,6 @@ namespace E2ETests.SmokeTestsUsingStore MusicStoreConfig.ConnectionStringKey, DbUtils.CreateConnectionString(musicStoreDbName))); - deploymentParameters.EnvironmentVariables.Add( - new KeyValuePair("DOTNET_SHARED_STORE", storeDirectory)); - using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) { var deploymentResult = await deployer.DeployAsync(); diff --git a/test/MusicStore.E2ETests/SmokeTestsUsingStore/Tests.cs b/test/MusicStore.E2ETests/SmokeTestsUsingStore/Tests.cs index c6a91f455a..1d65cfb616 100644 --- a/test/MusicStore.E2ETests/SmokeTestsUsingStore/Tests.cs +++ b/test/MusicStore.E2ETests/SmokeTestsUsingStore/Tests.cs @@ -1,21 +1,21 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System.Threading.Tasks; using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.Logging.Testing; using Xunit; using Xunit.Abstractions; namespace E2ETests.SmokeTestsUsingStore { - public class SmokeTests : IClassFixture + public class SmokeTests : LoggedTest { - private readonly StoreSetupFixture _testFixture; private readonly ITestOutputHelper _output; - public SmokeTests( - StoreSetupFixture testFixure, - ITestOutputHelper output) + public SmokeTests(ITestOutputHelper output): base(output) { - _testFixture = testFixure; _output = output; } @@ -25,9 +25,7 @@ namespace E2ETests.SmokeTestsUsingStore public async Task DefaultLocation_Kestrel() { var tests = new TestHelper(_output); - await tests.SmokeTestSuite( - ServerType.Kestrel, - _testFixture.StoreDirectory); + await tests.SmokeTestSuite(ServerType.Kestrel); } } } \ No newline at end of file