Skip to content

Commit

Permalink
Fixed bug where MergedLogFile would scramble the order of lines with …
Browse files Browse the repository at this point in the history
…identical timestamps compared to their original order

This occured due to the re-write sorting indices (using an unstable sort) before inserting them => Replaced with stable sort #154
  • Loading branch information
Kittyfisto committed May 28, 2019
1 parent 8a58132 commit 4520cbe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.IO;
using System.Threading;
using FluentAssertions;
using log4net.Core;
using NUnit.Framework;
using Tailviewer.BusinessLogic;
using Tailviewer.BusinessLogic.LogFiles;
Expand Down
5 changes: 2 additions & 3 deletions src/Tailviewer.Core/LogFiles/Merged/MergedLogFileIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,8 @@ private IReadOnlyList<MergedLogLineIndex> CreateIndices(
indices.AddRange(CreateIndices(entries, logFileIndex));
}

indices.Sort(new MergedLogLineIndexComparer());

return indices;
// TODO: Create unit test which fails if we don't use a stable sort...
return indices.OrderBy(x => x.Timestamp).ToList();
}

[Pure]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,33 @@ public void TestOneSourceResetAndAppend()
index.Count.Should().Be(1);
}

[Test]
public void TestOneSourceManySameTimestamps()
{
var source = new InMemoryLogFile();
source.AddEntry("A", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 053));
source.AddEntry("B", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 100));
source.AddEntry("C", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 100));
source.AddEntry("D", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 100));
source.AddEntry("E", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 115));
source.AddEntry("F", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 115));
source.AddEntry("G", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 115));
source.AddEntry("H", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 115));

var index = new MergedLogFileIndex(source);
index.Process(new MergedLogFilePendingModification(source, new LogFileSection(0, 8)));

var indices = index.Get(new LogFileSection(0, 8));
indices[0].SourceLineIndex.Should().Be(0);
indices[1].SourceLineIndex.Should().Be(1);
indices[2].SourceLineIndex.Should().Be(2);
indices[3].SourceLineIndex.Should().Be(3);
indices[4].SourceLineIndex.Should().Be(4);
indices[5].SourceLineIndex.Should().Be(5);
indices[6].SourceLineIndex.Should().Be(6);
indices[7].SourceLineIndex.Should().Be(7);
}

#region Skip log lines without timestamp

[Test]
Expand Down

0 comments on commit 4520cbe

Please sign in to comment.