Install store from artifact dependency
Instead of Build.RS package
This commit is contained in:
parent
aacd495943
commit
95f37a0edb
|
|
@ -15,10 +15,6 @@
|
||||||
<None Include="remoteDeploymentConfig.json" CopyToOutputDirectory="PreserveNewest" />
|
<None Include="remoteDeploymentConfig.json" CopyToOutputDirectory="PreserveNewest" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(RUN_RUNTIME_STORE_TESTS)' == 'true'">
|
|
||||||
<PackageReference Include="Build.RS" Version="$(AspNetCoreVersion)" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="$(AspNetCoreVersion)" />
|
||||||
|
|
|
||||||
|
|
@ -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<Store>();
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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<StoreSetupFixture> _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<StoreSetupFixture>();
|
|
||||||
|
|
||||||
_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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
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 targetFramework = "netcoreapp2.0";
|
||||||
var testName = $"SmokeTestsUsingStore_{serverType}";
|
var testName = $"SmokeTestsUsingStore_{serverType}";
|
||||||
|
|
@ -48,9 +51,6 @@ namespace E2ETests.SmokeTestsUsingStore
|
||||||
MusicStoreConfig.ConnectionStringKey,
|
MusicStoreConfig.ConnectionStringKey,
|
||||||
DbUtils.CreateConnectionString(musicStoreDbName)));
|
DbUtils.CreateConnectionString(musicStoreDbName)));
|
||||||
|
|
||||||
deploymentParameters.EnvironmentVariables.Add(
|
|
||||||
new KeyValuePair<string, string>("DOTNET_SHARED_STORE", storeDirectory));
|
|
||||||
|
|
||||||
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
|
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
|
||||||
{
|
{
|
||||||
var deploymentResult = await deployer.DeployAsync();
|
var deploymentResult = await deployer.DeployAsync();
|
||||||
|
|
|
||||||
|
|
@ -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 System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
||||||
using Microsoft.AspNetCore.Testing.xunit;
|
using Microsoft.AspNetCore.Testing.xunit;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
namespace E2ETests.SmokeTestsUsingStore
|
namespace E2ETests.SmokeTestsUsingStore
|
||||||
{
|
{
|
||||||
public class SmokeTests : IClassFixture<StoreSetupFixture>
|
public class SmokeTests : LoggedTest
|
||||||
{
|
{
|
||||||
private readonly StoreSetupFixture _testFixture;
|
|
||||||
private readonly ITestOutputHelper _output;
|
private readonly ITestOutputHelper _output;
|
||||||
|
|
||||||
public SmokeTests(
|
public SmokeTests(ITestOutputHelper output): base(output)
|
||||||
StoreSetupFixture testFixure,
|
|
||||||
ITestOutputHelper output)
|
|
||||||
{
|
{
|
||||||
_testFixture = testFixure;
|
|
||||||
_output = output;
|
_output = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,9 +25,7 @@ namespace E2ETests.SmokeTestsUsingStore
|
||||||
public async Task DefaultLocation_Kestrel()
|
public async Task DefaultLocation_Kestrel()
|
||||||
{
|
{
|
||||||
var tests = new TestHelper(_output);
|
var tests = new TestHelper(_output);
|
||||||
await tests.SmokeTestSuite(
|
await tests.SmokeTestSuite(ServerType.Kestrel);
|
||||||
ServerType.Kestrel,
|
|
||||||
_testFixture.StoreDirectory);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue