Skip to content

Commit

Permalink
Added some unit tests for new PostProcessHasDependencies flag
Browse files Browse the repository at this point in the history
  • Loading branch information
daveaglick committed Dec 29, 2022
1 parent 60410f4 commit c52add0
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 1 deletion.
55 changes: 54 additions & 1 deletion tests/core/Statiq.Core.Tests/Documents/PhaseOutputsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,59 @@ public void OutputPhaseFromDeploymentIgnoresNonExecutingNonDeploymentPipelines()
// Then
result.ShouldBe(new[] { b1, b2 }, true);
}

[Test]
public void PostProcessPhaseDoesNotGetDocumentsFromTransientDependencies()
{
// Given
TestDocument a1 = new TestDocument((NormalizedPath)"a1", "a1");
TestDocument b1 = new TestDocument((NormalizedPath)"b1", "b1");
TestDocument b2 = new TestDocument((NormalizedPath)"b2", "b2");
TestDocument c1 = new TestDocument((NormalizedPath)"c1", "c1");
ConcurrentDictionary<string, PhaseResult[]> phaseResults =
new ConcurrentDictionary<string, PhaseResult[]>(StringComparer.OrdinalIgnoreCase);
IPipelineCollection pipelines = new TestPipelineCollection();
PipelinePhase phaseA =
GetPipelineAndPhase("A", Phase.PostProcess, pipelines, phaseResults, new[] { a1 }, Phase.PostProcess);
PipelinePhase phaseB =
GetPipelineAndPhase("B", Phase.PostProcess, pipelines, phaseResults, new[] { b1, b2 }, Phase.PostProcess, phaseA);
PipelinePhase phaseC =
GetPipelineAndPhase("C", Phase.PostProcess, pipelines, phaseResults, new[] { c1 }, Phase.PostProcess, phaseB);
PhaseOutputs documentCollection = new PhaseOutputs(phaseResults, phaseC, pipelines);

// When
IDocument[] result = documentCollection.ToArray();

// Then
result.Select(x => x.Source).ShouldBeEmpty();
}

[Test]
public void PostProcessHasDependenciesPhaseGetsDocumentsFromTransientDependencies()
{
// Given
TestDocument a1 = new TestDocument((NormalizedPath)"a1", "a1");
TestDocument b1 = new TestDocument((NormalizedPath)"b1", "b1");
TestDocument b2 = new TestDocument((NormalizedPath)"b2", "b2");
TestDocument c1 = new TestDocument((NormalizedPath)"c1", "c1");
ConcurrentDictionary<string, PhaseResult[]> phaseResults =
new ConcurrentDictionary<string, PhaseResult[]>(StringComparer.OrdinalIgnoreCase);
IPipelineCollection pipelines = new TestPipelineCollection();
PipelinePhase phaseA =
GetPipelineAndPhase("A", Phase.PostProcess, pipelines, phaseResults, new[] { a1 }, Phase.PostProcess);
PipelinePhase phaseB =
GetPipelineAndPhase("B", Phase.PostProcess, pipelines, phaseResults, new[] { b1, b2 }, Phase.PostProcess, phaseA);
PipelinePhase phaseC =
GetPipelineAndPhase("C", Phase.PostProcess, pipelines, phaseResults, new[] { c1 }, Phase.PostProcess, phaseB);
phaseC.Pipeline.PostProcessHasDependencies = true;
PhaseOutputs documentCollection = new PhaseOutputs(phaseResults, phaseC, pipelines);

// When
IDocument[] result = documentCollection.ToArray();

// Then
result.Select(x => x.Source).ShouldBe(new NormalizedPath[] { "/input/a1", "/input/b1", "/input/b2" }, true);
}
}

public class ExceptPipelineTests : PhaseOutputsFixture
Expand Down Expand Up @@ -735,4 +788,4 @@ public void GetsDocumentsForInputPhaseDuringDeploymentOutputPhase()
params PipelinePhase[] dependencies) =>
GetPipelineAndPhase(pipelineName, phase, pipelines, phaseResults, outputs, Phase.Process, dependencies);
}
}
}
78 changes: 78 additions & 0 deletions tests/core/Statiq.Core.Tests/Execution/EngineFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,84 @@ public void DeploymentPipelinesDependOnOutputPhases()
.Select(x => (x.PipelineName, x.Phase))
.ShouldBeEmpty();
}

[Test]
public void ShouldAddProcessDependenciesToPostProcess()
{
// Given
IPipelineCollection pipelines = new TestPipelineCollection();
pipelines.Add("Bar", new TestPipeline
{
Dependencies = new HashSet<string>(new[] { "Foo" })
});
pipelines.Add("Foo", new TestPipeline());
ILogger logger = new TestLoggerProvider().CreateLogger(null);

// When
PipelinePhase[] phases = Engine.GetPipelinePhases(pipelines, logger);

// Then
phases.Select(x => (x.PipelineName, x.Phase)).ShouldBe(new (string, Phase)[]
{
("Foo", Phase.Input),
("Foo", Phase.Process),
("Bar", Phase.Input),
("Bar", Phase.Process),
("Foo", Phase.PostProcess),
("Foo", Phase.Output),
("Bar", Phase.PostProcess),
("Bar", Phase.Output),
});
phases.Single(x => x.PipelineName == "Bar" && x.Phase == Phase.PostProcess).Dependencies
.Select(x => (x.PipelineName, x.Phase))
.ShouldBe(
new (string, Phase)[]
{
("Bar", Phase.Process),
("Foo", Phase.Process)
},
true);
}

[Test]
public void ShouldAddPostProcessDependencyToPostProcess()
{
// Given
IPipelineCollection pipelines = new TestPipelineCollection();
pipelines.Add("Bar", new TestPipeline
{
PostProcessHasDependencies = true,
Dependencies = new HashSet<string>(new[] { "Foo" })
});
pipelines.Add("Foo", new TestPipeline());
ILogger logger = new TestLoggerProvider().CreateLogger(null);

// When
PipelinePhase[] phases = Engine.GetPipelinePhases(pipelines, logger);

// Then
phases.Select(x => (x.PipelineName, x.Phase)).ShouldBe(new (string, Phase)[]
{
("Foo", Phase.Input),
("Foo", Phase.Process),
("Bar", Phase.Input),
("Bar", Phase.Process),
("Foo", Phase.PostProcess),
("Foo", Phase.Output),
("Bar", Phase.PostProcess),
("Bar", Phase.Output),
});
phases.Single(x => x.PipelineName == "Bar" && x.Phase == Phase.PostProcess).Dependencies
.Select(x => (x.PipelineName, x.Phase))
.ShouldBe(
new (string, Phase)[]
{
("Bar", Phase.Process),
("Foo", Phase.Process),
("Foo", Phase.PostProcess)
},
true);
}
}

public class GetServiceTests : EngineFixture
Expand Down

0 comments on commit c52add0

Please sign in to comment.