Remove the need for a global lock when building or publishing a project (#21753)
* Change template test build and publish to not perform dotnet restore * Remove locking requirements for build and publish * Increase timeout for dotnet new operations since it's network bound
This commit is contained in:
parent
f87c1fc8c2
commit
b3c6c43789
|
|
@ -63,9 +63,9 @@ namespace Templates.Test.Helpers
|
|||
Timeout = TimeSpan.FromMinutes(2)
|
||||
};
|
||||
|
||||
output.WriteLine("Running ASP.NET application...");
|
||||
output.WriteLine("Running ASP.NET Core application...");
|
||||
|
||||
var arguments = published ? $"exec {dllPath}" : "run";
|
||||
var arguments = published ? $"exec {dllPath}" : "run --no-build";
|
||||
|
||||
logger?.LogInformation($"AspNetProcess - process: {DotNetMuxer.MuxerPathOrDefault()} arguments: {arguments}");
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Templates.Test.Helpers
|
|||
|
||||
public async Task WaitAsync(TimeSpan? timeout = null)
|
||||
{
|
||||
timeout ??= TimeSpan.FromMinutes(2);
|
||||
timeout ??= TimeSpan.FromMinutes(20);
|
||||
Assert.True(await Semaphore.WaitAsync(timeout.Value), $"Unable to acquire process lock for process {Name}");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -109,48 +109,30 @@ namespace Templates.Test.Helpers
|
|||
}
|
||||
}
|
||||
|
||||
internal async Task<ProcessResult> RunDotNetPublishAsync(bool takeNodeLock = false, IDictionary<string, string> packageOptions = null, string additionalArgs = null)
|
||||
internal async Task<ProcessResult> RunDotNetPublishAsync(IDictionary<string, string> packageOptions = null, string additionalArgs = null)
|
||||
{
|
||||
Output.WriteLine("Publishing ASP.NET application...");
|
||||
Output.WriteLine("Publishing ASP.NET Core application...");
|
||||
|
||||
// This is going to trigger a build, so we need to acquire the lock like in the other cases.
|
||||
// We want to take the node lock as some builds run NPM as part of the build and we want to make sure
|
||||
// it's run without interruptions.
|
||||
var effectiveLock = takeNodeLock ? new OrderedLock(NodeLock, DotNetNewLock) : new OrderedLock(nodeLock: null, DotNetNewLock);
|
||||
await effectiveLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"publish -c Release /bl {additionalArgs}", packageOptions);
|
||||
await result.Exited;
|
||||
CaptureBinLogOnFailure(result);
|
||||
return new ProcessResult(result);
|
||||
}
|
||||
finally
|
||||
{
|
||||
effectiveLock.Release();
|
||||
}
|
||||
// Avoid restoring as part of build or publish. These projects should have already restored as part of running dotnet new. Explicitly disabling restore
|
||||
// should avoid any global contention and we can execute a build or publish in a lock-free way
|
||||
|
||||
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"publish --no-restore -c Release /bl {additionalArgs}", packageOptions);
|
||||
await result.Exited;
|
||||
CaptureBinLogOnFailure(result);
|
||||
return new ProcessResult(result);
|
||||
}
|
||||
|
||||
internal async Task<ProcessResult> RunDotNetBuildAsync(bool takeNodeLock = false, IDictionary<string, string> packageOptions = null, string additionalArgs = null)
|
||||
internal async Task<ProcessResult> RunDotNetBuildAsync(IDictionary<string, string> packageOptions = null, string additionalArgs = null)
|
||||
{
|
||||
Output.WriteLine("Building ASP.NET application...");
|
||||
Output.WriteLine("Building ASP.NET Core application...");
|
||||
|
||||
// This is going to trigger a build, so we need to acquire the lock like in the other cases.
|
||||
// We want to take the node lock as some builds run NPM as part of the build and we want to make sure
|
||||
// it's run without interruptions.
|
||||
var effectiveLock = takeNodeLock ? new OrderedLock(NodeLock, DotNetNewLock) : new OrderedLock(nodeLock: null, DotNetNewLock);
|
||||
await effectiveLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"build -c Debug /bl {additionalArgs}", packageOptions);
|
||||
await result.Exited;
|
||||
CaptureBinLogOnFailure(result);
|
||||
return new ProcessResult(result);
|
||||
}
|
||||
finally
|
||||
{
|
||||
effectiveLock.Release();
|
||||
}
|
||||
// Avoid restoring as part of build or publish. These projects should have already restored as part of running dotnet new. Explicitly disabling restore
|
||||
// should avoid any global contention and we can execute a build or publish in a lock-free way
|
||||
|
||||
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"build --no-restore -c Debug /bl {additionalArgs}", packageOptions);
|
||||
await result.Exited;
|
||||
CaptureBinLogOnFailure(result);
|
||||
return new ProcessResult(result);
|
||||
}
|
||||
|
||||
internal AspNetProcess StartBuiltProjectAsync(bool hasListeningUri = true, ILogger logger = null)
|
||||
|
|
|
|||
Loading…
Reference in New Issue