Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove redundant sync and add large graph smoke test #630

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions Bullseye/Internal/TargetCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
Expand Down Expand Up @@ -27,7 +28,7 @@ public async Task RunAsync(IEnumerable<string> names, bool skipDependencies, boo

try
{
var runningTargets = new Dictionary<string, Task>();
var runningTargets = new ConcurrentDictionary<string, Task>();

using (var sync = new SemaphoreSlim(1, 1))
{
Expand All @@ -54,7 +55,7 @@ public async Task RunAsync(IEnumerable<string> names, bool skipDependencies, boo
await log.Succeeded(names).Tax();
}

private async Task RunAsync(string name, IEnumerable<string> explicitTargets, bool skipDependencies, bool dryRun, bool parallel, Logger log, Func<Exception, bool> messageOnly, Dictionary<string, Task> runningTargets, SemaphoreSlim sync, Stack<string> dependencyStack)
private async Task RunAsync(string name, IEnumerable<string> explicitTargets, bool skipDependencies, bool dryRun, bool parallel, Logger log, Func<Exception, bool> messageOnly, ConcurrentDictionary<string, Task> runningTargets, SemaphoreSlim sync, Stack<string> dependencyStack)
{
dependencyStack.Push(name);

Expand All @@ -66,22 +67,7 @@ private async Task RunAsync(string name, IEnumerable<string> explicitTargets, bo
return;
}

bool gotValue;
Task runningTarget;

// cannot use WaitAsync() as it is not reentrant
sync.Wait();

try
{
gotValue = runningTargets.TryGetValue(name, out runningTarget);
}
finally
{
_ = sync.Release();
}

if (gotValue)
if (runningTargets.TryGetValue(name, out var runningTarget))
{
await log.Verbose(dependencyStack, "Awaiting...").Tax();
await runningTarget.Tax();
Expand Down Expand Up @@ -117,7 +103,7 @@ private async Task RunAsync(string name, IEnumerable<string> explicitTargets, bo
if (!runningTargets.TryGetValue(name, out runningTarget))
{
runningTarget = target.RunAsync(dryRun, parallel, log, messageOnly);
runningTargets.Add(name, runningTarget);
_ = runningTargets.TryAdd(name, runningTarget);
}
}
finally
Expand Down
17 changes: 17 additions & 0 deletions BullseyeSmokeTester/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -101,8 +102,24 @@
targets.Add("def", DependsOn("abc"), () => Console.Out.WriteLine("def"));
targets.Add("default", DependsOn("def"));

var largeGraph = new Targets();
var largeGraphTargetNames = new List<string>();

foreach (var name in Enumerable.Range(1, 30).Select(i => i.ToString(CultureInfo.InvariantCulture)))
{
largeGraph.Add(name, largeGraphTargetNames.TakeLast(2), () => { });
largeGraphTargetNames.Add(name);
}

largeGraph.Add("large-graph", DependsOn(largeGraphTargetNames.Last()));

var (options, targetNames) = Options.Parse(args);

if (targetNames.Contains("large-graph"))
{
await largeGraph.RunAndExitAsync(targetNames, options);
}

if (!options.ShowHelp)
{
await targets.RunWithoutExitingAsync(targetNames, options);
Expand Down
2 changes: 2 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ dotnet run -c Release --no-build -p BullseyeSmokeTester -- --verbose || goto :er
dotnet run -c Release --no-build -p BullseyeSmokeTester -- -h --verbose || goto :error
dotnet run -c Release --no-build -p BullseyeSmokeTester -- -h --verbose --no-color || goto :error

dotnet run -c Release --no-build -p BullseyeSmokeTester -- large-graph --verbose --parallel || goto :error

dotnet run -c Release --no-build -p BullseyeSmokeTester.DragonFruit -- --help || goto :error
dotnet run -c Release --no-build -p BullseyeSmokeTester.DragonFruit -- --foo bar --verbose --targets build || goto :error

Expand Down
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dotnet run -c Release --no-build -p BullseyeSmokeTester -- --verbose
dotnet run -c Release --no-build -p BullseyeSmokeTester -- -h --verbose
dotnet run -c Release --no-build -p BullseyeSmokeTester -- -h --verbose --no-color

dotnet run -c Release --no-build -p BullseyeSmokeTester -- large-graph --verbose --parallel

dotnet run -c Release --no-build -p BullseyeSmokeTester.DragonFruit -- --help
dotnet run -c Release --no-build -p BullseyeSmokeTester.DragonFruit -- --foo bar --verbose --targets build

Expand Down