Skip to content

Commit

Permalink
Don't count insert nodes as patches
Browse files Browse the repository at this point in the history
As far as progress is concerned, these take much less time to apply than patches, and are often less numerous.  This can lead to weird completion percentages.
  • Loading branch information
blowfishpro committed Jan 10, 2019
1 parent 6ed6702 commit 1589e07
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ModuleManager/PatchApplier.cs
Expand Up @@ -41,7 +41,7 @@ private void ApplyPatches(LinkedList<IProtoUrlConfig> databaseConfigs, IPass pas
try
{
patch.Apply(databaseConfigs, progress, logger);
progress.PatchApplied();
if (patch.CountsAsPatch) progress.PatchApplied();
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion ModuleManager/PatchList.cs
Expand Up @@ -126,7 +126,7 @@ public PatchList(IEnumerable<string> modList, IEnumerable<IPatch> patches, IPatc
throw new NotImplementedException("Don't know what to do with pass specifier: " + patch.PassSpecifier.Descriptor);
}

progress.PatchAdded();
if (patch.CountsAsPatch) progress.PatchAdded();
}
}

Expand Down
1 change: 1 addition & 0 deletions ModuleManager/Patches/CopyPatch.cs
Expand Up @@ -13,6 +13,7 @@ public class CopyPatch : IPatch
public UrlDir.UrlConfig UrlConfig { get; }
public INodeMatcher NodeMatcher { get; }
public IPassSpecifier PassSpecifier { get; }
public bool CountsAsPatch => true;

public CopyPatch(UrlDir.UrlConfig urlConfig, INodeMatcher nodeMatcher, IPassSpecifier passSpecifier)
{
Expand Down
1 change: 1 addition & 0 deletions ModuleManager/Patches/DeletePatch.cs
Expand Up @@ -12,6 +12,7 @@ public class DeletePatch : IPatch
public UrlDir.UrlConfig UrlConfig { get; }
public INodeMatcher NodeMatcher { get; }
public IPassSpecifier PassSpecifier { get; }
public bool CountsAsPatch => true;

public DeletePatch(UrlDir.UrlConfig urlConfig, INodeMatcher nodeMatcher, IPassSpecifier passSpecifier)
{
Expand Down
1 change: 1 addition & 0 deletions ModuleManager/Patches/EditPatch.cs
Expand Up @@ -15,6 +15,7 @@ public class EditPatch : IPatch
public UrlDir.UrlConfig UrlConfig { get; }
public INodeMatcher NodeMatcher { get; }
public IPassSpecifier PassSpecifier { get; }
public bool CountsAsPatch => true;

public EditPatch(UrlDir.UrlConfig urlConfig, INodeMatcher nodeMatcher, IPassSpecifier passSpecifier)
{
Expand Down
1 change: 1 addition & 0 deletions ModuleManager/Patches/IPatch.cs
Expand Up @@ -10,6 +10,7 @@ public interface IPatch
{
UrlDir.UrlConfig UrlConfig { get; }
IPassSpecifier PassSpecifier { get; }
bool CountsAsPatch { get; }
void Apply(LinkedList<IProtoUrlConfig> configs, IPatchProgress progress, IBasicLogger logger);
}
}
1 change: 1 addition & 0 deletions ModuleManager/Patches/InsertPatch.cs
Expand Up @@ -12,6 +12,7 @@ public class InsertPatch : IPatch
public UrlDir.UrlConfig UrlConfig { get; }
public string NodeType { get; }
public IPassSpecifier PassSpecifier { get; }
public bool CountsAsPatch => false;

public InsertPatch(UrlDir.UrlConfig urlConfig, string nodeType, IPassSpecifier passSpecifier)
{
Expand Down
13 changes: 10 additions & 3 deletions ModuleManagerTests/PatchApplierTest.cs
Expand Up @@ -67,6 +67,16 @@ public void TestApplyPatches()
patches[i] = Substitute.For<IPatch>();
}

patches[0].CountsAsPatch.Returns(false);
patches[1].CountsAsPatch.Returns(false);
patches[2].CountsAsPatch.Returns(false);
patches[3].CountsAsPatch.Returns(true);
patches[4].CountsAsPatch.Returns(true);
patches[5].CountsAsPatch.Returns(true);
patches[6].CountsAsPatch.Returns(true);
patches[7].CountsAsPatch.Returns(true);
patches[8].CountsAsPatch.Returns(true);

pass1.GetEnumerator().Returns(new ArrayEnumerator<IPatch>(patches[0], patches[1], patches[2]));
pass2.GetEnumerator().Returns(new ArrayEnumerator<IPatch>(patches[3], patches[4], patches[5]));
pass3.GetEnumerator().Returns(new ArrayEnumerator<IPatch>(patches[6], patches[7], patches[8]));
Expand All @@ -87,11 +97,8 @@ public void TestApplyPatches()
{
progress.PassStarted(pass1);
patches[0].Apply(databaseConfigs, progress, logger);
progress.PatchApplied();
patches[1].Apply(databaseConfigs, progress, logger);
progress.PatchApplied();
patches[2].Apply(databaseConfigs, progress, logger);
progress.PatchApplied();
progress.PassStarted(pass2);
patches[3].Apply(databaseConfigs, progress, logger);
progress.PatchApplied();
Expand Down
27 changes: 26 additions & 1 deletion ModuleManagerTests/PatchListTest.cs
Expand Up @@ -142,6 +142,31 @@ public void Test__Lifecycle()
patches[22].PassSpecifier.Returns(new FinalPassSpecifier());
patches[23].PassSpecifier.Returns(new FinalPassSpecifier());

patches[00].CountsAsPatch.Returns(false);
patches[01].CountsAsPatch.Returns(false);
patches[02].CountsAsPatch.Returns(true);
patches[03].CountsAsPatch.Returns(true);
patches[04].CountsAsPatch.Returns(true);
patches[05].CountsAsPatch.Returns(true);
patches[06].CountsAsPatch.Returns(true);
patches[07].CountsAsPatch.Returns(true);
patches[08].CountsAsPatch.Returns(true);
patches[09].CountsAsPatch.Returns(true);
patches[10].CountsAsPatch.Returns(true);
patches[11].CountsAsPatch.Returns(true);
patches[12].CountsAsPatch.Returns(true);
patches[13].CountsAsPatch.Returns(true);
patches[14].CountsAsPatch.Returns(true);
patches[15].CountsAsPatch.Returns(true);
patches[16].CountsAsPatch.Returns(true);
patches[17].CountsAsPatch.Returns(true);
patches[18].CountsAsPatch.Returns(true);
patches[19].CountsAsPatch.Returns(true);
patches[20].CountsAsPatch.Returns(true);
patches[21].CountsAsPatch.Returns(true);
patches[22].CountsAsPatch.Returns(true);
patches[23].CountsAsPatch.Returns(true);

IPatchProgress progress = Substitute.For<IPatchProgress>();

PatchList patchList = new PatchList(new[] { "mod1", "mod2" }, patches, progress);
Expand Down Expand Up @@ -186,7 +211,7 @@ public void Test__Lifecycle()
Assert.Equal(":FINAL", passes[11].Name);
Assert.Equal(new[] { patches[22], patches[23] }, passes[11]);

progress.Received(patches.Length).PatchAdded();
progress.Received(22).PatchAdded();
}
}
}
7 changes: 7 additions & 0 deletions ModuleManagerTests/Patches/CopyPatchTest.cs
Expand Up @@ -74,6 +74,13 @@ public void TestPassSpecifier()
Assert.Same(passSpecifier, patch.PassSpecifier);
}

[Fact]
public void TestCountsAsPatch()
{
CopyPatch patch = new CopyPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), Substitute.For<INodeMatcher>(), Substitute.For<IPassSpecifier>());
Assert.True(patch.CountsAsPatch);
}

[Fact]
public void TestApply()
{
Expand Down
7 changes: 7 additions & 0 deletions ModuleManagerTests/Patches/DeletePatchTest.cs
Expand Up @@ -73,6 +73,13 @@ public void TestPassSpecifier()
Assert.Same(passSpecifier, patch.PassSpecifier);
}

[Fact]
public void TestCountsAsPatch()
{
DeletePatch patch = new DeletePatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), Substitute.For<INodeMatcher>(), Substitute.For<IPassSpecifier>());
Assert.True(patch.CountsAsPatch);
}

[Fact]
public void TestApply()
{
Expand Down
7 changes: 7 additions & 0 deletions ModuleManagerTests/Patches/EditPatchTest.cs
Expand Up @@ -75,6 +75,13 @@ public void TestPassSpecifier()
Assert.Same(passSpecifier, patch.PassSpecifier);
}

[Fact]
public void TestCountsAsPatch()
{
EditPatch patch = new EditPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), Substitute.For<INodeMatcher>(), Substitute.For<IPassSpecifier>());
Assert.True(patch.CountsAsPatch);
}

[Fact]
public void TestApply()
{
Expand Down
7 changes: 7 additions & 0 deletions ModuleManagerTests/Patches/InsertPatchTest.cs
Expand Up @@ -73,6 +73,13 @@ public void TestPassSpecifier()

Assert.Same(passSpecifier, patch.PassSpecifier);
}

[Fact]
public void TestCountsAsPatch()
{
InsertPatch patch = new InsertPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), "A_NODE", Substitute.For<IPassSpecifier>());
Assert.False(patch.CountsAsPatch);
}

[Fact]
public void TestApply()
Expand Down

0 comments on commit 1589e07

Please sign in to comment.