Add tests for "half-portable" scenario
This commit is contained in:
parent
2d3a1fd177
commit
14770ae5ba
15 changed files with 200 additions and 53 deletions
|
@ -9,7 +9,7 @@
|
|||
"emitEntryPoint": true
|
||||
},
|
||||
"compile": [
|
||||
"../../../TestProjects/KestrelSample/src/*.cs"
|
||||
"../src/*.cs"
|
||||
],
|
||||
"frameworks": {
|
||||
"net451": { }
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"emitEntryPoint": true
|
||||
},
|
||||
"compile": [
|
||||
"../../../TestProjects/KestrelSample/src/*.cs"
|
||||
"../src/*.cs"
|
||||
],
|
||||
"frameworks": {
|
||||
"net451": { }
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
// 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.IO;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Server.Kestrel;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Filter;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
|
||||
namespace SampleApp
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
private static string Args { get; set; }
|
||||
private static CancellationTokenSource ServerCancellationTokenSource { get; set; }
|
||||
|
||||
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env)
|
||||
{
|
||||
var ksi = app.ServerFeatures.Get<IKestrelServerInformation>();
|
||||
ksi.NoDelay = true;
|
||||
|
||||
loggerFactory.AddConsole(LogLevel.Error);
|
||||
|
||||
app.UseKestrelConnectionLogging();
|
||||
|
||||
app.Run(async context =>
|
||||
{
|
||||
Console.WriteLine("{0} {1}{2}{3}",
|
||||
context.Request.Method,
|
||||
context.Request.PathBase,
|
||||
context.Request.Path,
|
||||
context.Request.QueryString);
|
||||
Console.WriteLine($"Method: {context.Request.Method}");
|
||||
Console.WriteLine($"PathBase: {context.Request.PathBase}");
|
||||
Console.WriteLine($"Path: {context.Request.Path}");
|
||||
Console.WriteLine($"QueryString: {context.Request.QueryString}");
|
||||
|
||||
var connectionFeature = context.Connection;
|
||||
Console.WriteLine($"Peer: {connectionFeature.RemoteIpAddress?.ToString()} {connectionFeature.RemotePort}");
|
||||
Console.WriteLine($"Sock: {connectionFeature.LocalIpAddress?.ToString()} {connectionFeature.LocalPort}");
|
||||
|
||||
var content = $"Hello world!{Environment.NewLine}Received '{Args}' from command line.";
|
||||
context.Response.ContentLength = content.Length;
|
||||
context.Response.ContentType = "text/plain";
|
||||
await context.Response.WriteAsync(content);
|
||||
});
|
||||
}
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
Console.WriteLine("KestrelHelloWorld <url to host>");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var url = new Uri(args[0]);
|
||||
Args = string.Join(" ", args);
|
||||
|
||||
var host = new WebHostBuilder()
|
||||
.UseServer("Microsoft.AspNetCore.Server.Kestrel")
|
||||
.UseUrls(url.ToString())
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
|
||||
ServerCancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
// shutdown server after 20s.
|
||||
var shutdownTask = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(20000);
|
||||
ServerCancellationTokenSource.Cancel();
|
||||
});
|
||||
|
||||
host.Run(ServerCancellationTokenSource.Token);
|
||||
shutdownTask.Wait();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,8 +9,9 @@
|
|||
<ProjectGuid>c26a48bb-193f-450c-ab09-4d3324c78188</ProjectGuid>
|
||||
<RootNamespace>dotnet-dependency-tool-invoker</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\</OutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
<ProjectGuid>da8e0e9e-a6d6-4583-864c-8f40465e3a48</ProjectGuid>
|
||||
<RootNamespace>TestAppWithArgs</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\</OutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
<ProjectGuid>0138cb8f-4aa9-4029-a21e-c07c30f425ba</ProjectGuid>
|
||||
<RootNamespace>TestAppWithContents</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\</OutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -248,6 +248,7 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
CleanOutputDir(Path.Combine(Dirs.Stage1, "sdk"));
|
||||
FS.CopyRecursive(Dirs.Stage1, Dirs.Stage1Symbols);
|
||||
|
||||
RemovePdbsFromDir(Path.Combine(Dirs.Stage1, "sdk"));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -300,6 +301,8 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
CleanOutputDir(Path.Combine(Dirs.Stage2, "sdk"));
|
||||
FS.CopyRecursive(Dirs.Stage2, Dirs.Stage2Symbols);
|
||||
|
||||
RemovePdbsFromDir(Path.Combine(Dirs.Stage2, "sdk"));
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
|
|
|
@ -200,7 +200,6 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
.Execute();
|
||||
}
|
||||
|
||||
|
||||
var projectJson = Path.Combine(fullPath, "project.json");
|
||||
var dotnetPackArgs = new List<string> {
|
||||
projectJson,
|
||||
|
|
|
@ -9,33 +9,9 @@ using Microsoft.DotNet.ProjectModel.Compilation;
|
|||
using Microsoft.DotNet.ProjectModel.Graph;
|
||||
using Microsoft.DotNet.ProjectModel.Resolution;
|
||||
using NuGet.Frameworks;
|
||||
using NuGet.RuntimeModel;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectModel
|
||||
{
|
||||
class RuntimeGraphCollector
|
||||
{
|
||||
private const string RuntimeJsonFileName = "runtime.json";
|
||||
|
||||
public static RuntimeGraph Collect(IEnumerable<LibraryDescription> libraries)
|
||||
{
|
||||
var graph = RuntimeGraph.Empty;
|
||||
foreach (var library in libraries)
|
||||
{
|
||||
if (library.Identity.Type == LibraryType.Package)
|
||||
{
|
||||
var runtimeJson = ((PackageDescription)library).PackageLibrary.Files.FirstOrDefault(f => f == RuntimeJsonFileName);
|
||||
if (runtimeJson != null)
|
||||
{
|
||||
var runtimeJsonFullName = Path.Combine(library.Path, runtimeJson);
|
||||
graph = RuntimeGraph.Merge(graph, JsonRuntimeFormat.ReadRuntimeGraph(runtimeJsonFullName));
|
||||
}
|
||||
}
|
||||
}
|
||||
return graph;
|
||||
}
|
||||
}
|
||||
|
||||
public class ProjectContext
|
||||
{
|
||||
private string[] _runtimeFallbacks;
|
||||
|
|
|
@ -209,6 +209,8 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
bool isPortable = platformDependency != null || TargetFramework.IsDesktop();
|
||||
|
||||
LockFileTarget target = null;
|
||||
LibraryDescription platformLibrary = null;
|
||||
|
||||
if (lockFileLookup != null)
|
||||
{
|
||||
target = SelectTarget(LockFile, isPortable);
|
||||
|
@ -217,6 +219,11 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
var nugetPackageResolver = new PackageDependencyProvider(PackagesDirectory, frameworkReferenceResolver);
|
||||
var msbuildProjectResolver = new MSBuildDependencyProvider(Project, ProjectResolver);
|
||||
ScanLibraries(target, lockFileLookup, libraries, msbuildProjectResolver, nugetPackageResolver, projectResolver);
|
||||
|
||||
if (platformDependency != null)
|
||||
{
|
||||
platformLibrary = libraries[new LibraryKey(platformDependency.Value.Name)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,12 +245,6 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
runtime = target?.RuntimeIdentifier;
|
||||
}
|
||||
|
||||
LibraryDescription platformLibrary = null;
|
||||
if(platformDependency != null)
|
||||
{
|
||||
platformLibrary = libraries[new LibraryKey(platformDependency.Value.Name)];
|
||||
}
|
||||
|
||||
var referenceAssemblyDependencyResolver = new ReferenceAssemblyDependencyResolver(frameworkReferenceResolver);
|
||||
bool requiresFrameworkAssemblies;
|
||||
|
||||
|
|
34
src/Microsoft.DotNet.ProjectModel/RuntimeGraphCollector.cs
Normal file
34
src/Microsoft.DotNet.ProjectModel/RuntimeGraphCollector.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.ProjectModel.Graph;
|
||||
using NuGet.RuntimeModel;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectModel
|
||||
{
|
||||
class RuntimeGraphCollector
|
||||
{
|
||||
private const string RuntimeJsonFileName = "runtime.json";
|
||||
|
||||
public static RuntimeGraph Collect(IEnumerable<LibraryDescription> libraries)
|
||||
{
|
||||
var graph = RuntimeGraph.Empty;
|
||||
foreach (var library in libraries)
|
||||
{
|
||||
if (library.Identity.Type == LibraryType.Package)
|
||||
{
|
||||
var runtimeJson = ((PackageDescription)library).PackageLibrary.Files.FirstOrDefault(f => f == RuntimeJsonFileName);
|
||||
if (runtimeJson != null)
|
||||
{
|
||||
var runtimeJsonFullName = Path.Combine(library.Path, runtimeJson);
|
||||
graph = RuntimeGraph.Merge(graph, JsonRuntimeFormat.ReadRuntimeGraph(runtimeJsonFullName));
|
||||
}
|
||||
}
|
||||
}
|
||||
return graph;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -161,7 +161,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
Debug.Assert(targets.Count == 1);
|
||||
}
|
||||
|
||||
//Debug.Assert(targets.All(t => string.IsNullOrEmpty(t.RuntimeIdentifier)));
|
||||
Debug.Assert(targets.All(t => string.IsNullOrEmpty(t.RuntimeIdentifier)));
|
||||
|
||||
var success = execute(targets, this);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<ProjectGuid>0B31C336-149D-471A-B7B1-27B0F1E80F83</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Cli.Msi.Tests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\</OutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
|
|
|
@ -7,6 +7,7 @@ using Microsoft.Extensions.PlatformAbstractions;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
|
@ -42,6 +43,12 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
_buidBasePathDirectory = buildBasePath;
|
||||
}
|
||||
|
||||
public override Task<CommandResult> ExecuteAsync(string args = "")
|
||||
{
|
||||
args = $"publish {BuildArgs()} {args}";
|
||||
return base.ExecuteAsync(args);
|
||||
}
|
||||
|
||||
public override CommandResult Execute(string args = "")
|
||||
{
|
||||
args = $"publish {BuildArgs()} {args}";
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
@ -11,30 +13,60 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
public class PublishDesktopTests : TestBase
|
||||
{
|
||||
[WindowsOnlyTheory]
|
||||
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20201", null)]
|
||||
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20201", "win7-x64")]
|
||||
[InlineData("KestrelDesktop", "http://localhost:20203", null)]
|
||||
[InlineData("KestrelDesktop", "http://localhost:20204", "win7-x64")]
|
||||
public async Task DesktopApp_WithKestrel_WorksWhenPublishedWithRID(string project, string url, string runtime)
|
||||
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20201", null, "libuv.dll", true)]
|
||||
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20202", "win7-x64", "libuv.dll", true)]
|
||||
[InlineData("KestrelDesktop", "http://localhost:20204", null, "libuv.dll", true)]
|
||||
[InlineData("KestrelDesktop", "http://localhost:20205", "win7-x64", "libuv.dll", true)]
|
||||
public async Task DesktopApp_WithKestrel_WorksWhenPublished(string project, string url, string runtime, string libuvName, bool runnable)
|
||||
{
|
||||
var testInstance = GetTestInstance(project)
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
var testInstance = GetTestInstance()
|
||||
.WithLockFiles();
|
||||
|
||||
var publishCommand = new PublishCommand(testInstance.TestRoot, runtime);
|
||||
var publishCommand = new PublishCommand(Path.Combine(testInstance.TestRoot, project), runtime: runtime);
|
||||
var result = await publishCommand.ExecuteAsync();
|
||||
|
||||
result.Should().Pass();
|
||||
|
||||
// Test the output
|
||||
var outputDir = publishCommand.GetOutputDirectory(portable: false);
|
||||
outputDir.Should().HaveFile("libuv.dll");
|
||||
outputDir.Should().HaveFile(libuvName);
|
||||
outputDir.Should().HaveFile(publishCommand.GetOutputExecutable());
|
||||
|
||||
var command = new TestCommand(Path.Combine(outputDir.FullName, publishCommand.GetOutputExecutable()));
|
||||
Task exec = null;
|
||||
if (runnable)
|
||||
{
|
||||
var command = new TestCommand(Path.Combine(outputDir.FullName, publishCommand.GetOutputExecutable()));
|
||||
try
|
||||
{
|
||||
exec = command.ExecuteAsync(url);
|
||||
NetworkHelper.IsServerUp(url).Should().BeTrue($"Unable to connect to kestrel server - {project} @ {url}");
|
||||
NetworkHelper.TestGetRequest(url, url);
|
||||
}
|
||||
finally
|
||||
{
|
||||
command.KillTree();
|
||||
}
|
||||
if (exec != null)
|
||||
{
|
||||
await exec;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[WindowsOnlyTheory]
|
||||
[InlineData("KestrelDesktop", "http://localhost:20207")]
|
||||
[InlineData("KestrelDesktopWithRuntimes", "http://localhost:20208")]
|
||||
public async Task DesktopApp_WithKestrel_WorksWhenRun(string project, string url)
|
||||
{
|
||||
var testInstance = GetTestInstance()
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
|
||||
Task exec = null;
|
||||
var command = new RunCommand(Path.Combine(testInstance.TestRoot, project));
|
||||
try
|
||||
{
|
||||
command.Execute(url);
|
||||
exec = command.ExecuteAsync(url);
|
||||
NetworkHelper.IsServerUp(url).Should().BeTrue($"Unable to connect to kestrel server - {project} @ {url}");
|
||||
NetworkHelper.TestGetRequest(url, url);
|
||||
}
|
||||
|
@ -42,11 +74,15 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
{
|
||||
command.KillTree();
|
||||
}
|
||||
if (exec != null)
|
||||
{
|
||||
await exec;
|
||||
}
|
||||
}
|
||||
|
||||
private static TestInstance GetTestInstance(string name)
|
||||
private static TestInstance GetTestInstance([CallerMemberName] string callingMethod = "")
|
||||
{
|
||||
return TestAssetsManager.CreateTestInstance(Path.Combine("..", "DesktopTestProjects", "DesktopKestrelSample", name));
|
||||
return TestAssetsManager.CreateTestInstance(Path.Combine("..", "DesktopTestProjects", "DesktopKestrelSample"), callingMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue