-
Notifications
You must be signed in to change notification settings - Fork 184
Csv problems fix #577
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
Merged
Merged
Csv problems fix #577
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f3ec5e9
a few changes
2e454d8
single line not showing bugfix
5dc1c3d
regression tests
fb45312
chore: update plugin hashes [skip ci]
github-actions[bot] 8027f96
review comments
27170e1
Merge branch 'csv_problems_fix' of https://github.com/LogExperts/LogE…
5b47e1e
chore: update plugin hashes [skip ci]
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
445 changes: 445 additions & 0 deletions
445
src/LogExpert.Tests/ColumnizerTests/CSVColumnizerTest.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| using ColumnizerLib; | ||
|
|
||
| using LogExpert.Core.Callback; | ||
| using LogExpert.Core.Interfaces; | ||
| using LogExpert.UI.Controls.LogWindow; | ||
|
|
||
| using Moq; | ||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| namespace LogExpert.Tests.Controls; | ||
|
|
||
| [TestFixture] | ||
| public class ColumnCacheTests | ||
| { | ||
| /// <summary> | ||
| /// Regression test for a cache-poisoning bug in <see cref="ColumnCache.GetColumnsForLine"/>: | ||
| /// when the underlying <see cref="ILogfileReader.GetLogLineMemoryWithWait"/> returned null | ||
| /// (e.g. fast-fail timeout) for a given line, the cache stored that null and | ||
| /// permanently returned null for every subsequent request of the same line number. | ||
| /// This manifested in the GUI as a blank data row in a CSV file containing a header | ||
| /// plus exactly one data line (header was dropped by CsvColumnizer's PreProcessLine, | ||
| /// leaving a single grid row that was repeatedly requested for paint). | ||
| /// The fix adds <c>_cachedColumns == null</c> to the re-fetch condition so a null | ||
| /// result is never cached. | ||
| /// </summary> | ||
| [Test] | ||
| public void GetColumnsForLine_NullThenValidLine_ReturnsColumnsOnSecondCall () | ||
| { | ||
| const int lineNumber = 0; | ||
|
|
||
| var validLine = new Mock<ILogLineMemory>().Object; | ||
| var splitResult = new Mock<IColumnizedLogLineMemory>().Object; | ||
|
|
||
| var readerMock = new Mock<ILogfileReader>(); | ||
| readerMock | ||
| .SetupSequence(r => r.GetLogLineMemoryWithWait(lineNumber)) | ||
| .Returns(Task.FromResult<ILogLineMemory>(null)) | ||
| .Returns(Task.FromResult(validLine)); | ||
|
|
||
| var columnizerMock = new Mock<ILogLineMemoryColumnizer>(); | ||
| columnizerMock | ||
| .Setup(c => c.SplitLine(It.IsAny<ILogLineMemoryColumnizerCallback>(), validLine)) | ||
| .Returns(splitResult); | ||
|
|
||
| var logWindowMock = new Mock<ILogWindow>(); | ||
| var callback = new ColumnizerCallback(logWindowMock.Object); | ||
|
|
||
| var cache = new ColumnCache(); | ||
|
|
||
| // First call: reader returns null -> cache must NOT store this null. | ||
| var firstResult = cache.GetColumnsForLine(readerMock.Object, lineNumber, columnizerMock.Object, callback); | ||
| Assert.That(firstResult, Is.Null, "First call should return null because the reader returned null."); | ||
|
|
||
| // Second call for the SAME line: reader now returns a valid line. | ||
| // Before the fix this would return the cached null and never call SplitLine. | ||
| var secondResult = cache.GetColumnsForLine(readerMock.Object, lineNumber, columnizerMock.Object, callback); | ||
|
|
||
| Assert.That(secondResult, Is.SameAs(splitResult), "Second call must re-fetch and return the freshly split columns instead of a cached null."); | ||
| readerMock.Verify(r => r.GetLogLineMemoryWithWait(lineNumber), Times.Exactly(2)); | ||
| columnizerMock.Verify(c => c.SplitLine(It.IsAny<ILogLineMemoryColumnizerCallback>(), validLine), Times.Once); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sanity check that a valid result IS cached: requesting the same line twice | ||
| /// with a successful first fetch must not call the reader/columnizer a second time. | ||
| /// </summary> | ||
| [Test] | ||
| public void GetColumnsForLine_SameLineTwice_UsesCachedValue () | ||
| { | ||
| const int lineNumber = 0; | ||
|
|
||
| var validLine = new Mock<ILogLineMemory>().Object; | ||
| var splitResult = new Mock<IColumnizedLogLineMemory>().Object; | ||
|
|
||
| var readerMock = new Mock<ILogfileReader>(); | ||
| readerMock | ||
| .Setup(r => r.GetLogLineMemoryWithWait(lineNumber)) | ||
| .Returns(Task.FromResult(validLine)); | ||
|
|
||
| var columnizerMock = new Mock<ILogLineMemoryColumnizer>(); | ||
| columnizerMock | ||
| .Setup(c => c.SplitLine(It.IsAny<ILogLineMemoryColumnizerCallback>(), validLine)) | ||
| .Returns(splitResult); | ||
|
|
||
| var logWindowMock = new Mock<ILogWindow>(); | ||
| var callback = new ColumnizerCallback(logWindowMock.Object); | ||
|
|
||
| var cache = new ColumnCache(); | ||
|
|
||
| var firstResult = cache.GetColumnsForLine(readerMock.Object, lineNumber, columnizerMock.Object, callback); | ||
| // callback.LineNum is now equal to lineNumber (set by GetColumnsForLine), so the | ||
| // second call should hit the cache. | ||
| var secondResult = cache.GetColumnsForLine(readerMock.Object, lineNumber, columnizerMock.Object, callback); | ||
|
|
||
| Assert.That(firstResult, Is.SameAs(splitResult)); | ||
| Assert.That(secondResult, Is.SameAs(splitResult)); | ||
| readerMock.Verify(r => r.GetLogLineMemoryWithWait(lineNumber), Times.Once); | ||
| columnizerMock.Verify(c => c.SplitLine(It.IsAny<ILogLineMemoryColumnizerCallback>(), validLine), Times.Once); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| "Date","Level","Message" | ||
| "2021-01-01","Error","comma file" | ||
| "2021-01-01","Error","comma file" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| "Date","Level","Message" | ||
| "2021-01-01","Error","comma file" | ||
| "2021-01-01","Error","comma file" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| "Date";"Level";"Message" | ||
| "2021-12-12";"TRACE";"semicolon file " | ||
| "2021-12-12";"TRACE";"semicolon file " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| "Date";"Level";"Message" | ||
| "2021-12-12";"TRACE";"semicolon file " | ||
| "2021-12-12";"TRACE";"semicolon file " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| "Date" "Level" "Message" | ||
| "2023-05-01" "INFO" "tab file" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| "Date" "Level" "Message" | ||
| "2023-05-01" "INFO" "tab file" | ||
| "2023-05-01" "INFO" "tab file" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.