Permalink
Browse files

evolve ActionScheduler

  • Loading branch information...
1 parent 721d110 commit 4df7360bddaa16ba8fae6de6ed86fb4b5f721af3 Lucas Meijer committed Apr 15, 2012
Showing with 27 additions and 3 deletions.
  1. +13 −3 ActionScheduler.cs
  2. +14 −0 Tests/ActionSchedulerTest.cs
View
@@ -1,15 +1,16 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Linq;
namespace cake
{
public class ActionScheduler
{
- private Dictionary<TargetGenerateSettings, List<string>> _scheduledActions = new Dictionary<TargetGenerateSettings, List<string>>();
+ private readonly Dictionary<TargetGenerateSettings, HashSet<string>> _scheduledActions = new Dictionary<TargetGenerateSettings, HashSet<string>>();
public void Add(IEnumerable<string> dependenciesRequiringRegeneration, TargetGenerateSettings tgs)
{
- _scheduledActions.Add(tgs, new List<string>(dependenciesRequiringRegeneration));
+ _scheduledActions.Add(tgs, new HashSet<string>(dependenciesRequiringRegeneration));
}
public TargetGenerateSettings FindJobToRun()
@@ -19,5 +20,14 @@ public TargetGenerateSettings FindJobToRun()
_scheduledActions.Remove(findJobToRun);
return findJobToRun;
}
+
+ public void JobFinished(TargetGenerateSettings finishedJob)
+ {
+ foreach(var outputFile in finishedJob.OutputFiles)
+ {
+ foreach (var deps in _scheduledActions.Values)
+ deps.Remove(outputFile);
+ }
+ }
}
}
@@ -48,5 +48,19 @@ public void SingleActionWithDependenciesRequiringGenerationCannotBeRun()
Assert.IsNull(_scheduler.FindJobToRun());
}
+ [Test]
+ public void ActionWithDependenciesRequiringGenerationCanBeRanWhenDependencyIsGenerated()
+ {
+ var tgs = new TargetGenerateSettings(_action, new[] { "input" }, "output");
+ _scheduler.Add(new[] { "input" }, tgs);
+
+ Assert.IsNull(_scheduler.FindJobToRun());
+
+ var inputGenerator = new TargetGenerateSettings(_action, new string[0], "input");
+ _scheduler.JobFinished(inputGenerator);
+
+ Assert.AreEqual(tgs,_scheduler.FindJobToRun());
+ }
+
}
}

0 comments on commit 4df7360

Please sign in to comment.