Skip to content

Commit

Permalink
[AgentWorker.PageLogger] - Ignore endgroup tag when counting lines (#…
Browse files Browse the repository at this point in the history
…4666)

* [AgentWorker.PageLogger] - Ignore endgroup tag when counting lines

- Added case insensitive search
- Added tests for the new logic

* [AgentWorker.PageLogger] - Ignore endgroup tag when counting lines

- Added case insensitive search
- Added tests for the new logic
  • Loading branch information
DmitriiBobreshev authored Feb 20, 2024
1 parent a5f98f1 commit c3e3209
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Microsoft.VisualStudio.Services.Agent/Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public void Write(string message)
Create();
}

if (message.Contains(groupStartTag))
if (message.Contains(groupStartTag, StringComparison.OrdinalIgnoreCase))
{
_groupOpened = true;
}
if (_groupOpened && message.Contains(groupEndTag))
if (_groupOpened && message.Contains(groupEndTag, StringComparison.OrdinalIgnoreCase))
{
// Ignore group end tag only if group was opened, otherwise it is a normal message
// because in web console ##[endgroup] becomes empty line without ##[group] tag
Expand Down
51 changes: 51 additions & 0 deletions src/Test/L0/PagingLoggerL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public sealed class PagingLoggerL0
##[group]sage
messagemessagemessagemessage
XPLATmessagemessagemessagemessagemessagemessagemessagemessage";
private const string LogDataUpperCaseGroup = @"messagemessagemessagemes
##[GROUP]sage
messagemessagemessagemessage
##[ENDGROUP]
XPLATmessagemessagemessagemessagemessagemessagemessagemessage";
private const int PagesToWrite = 2;
private Mock<IJobServerQueue> _jobServerQueue;

Expand Down Expand Up @@ -327,5 +332,51 @@ public void CalculateLineNumbersWithoutCloseGroupTag()
CleanLogFolder();
}
}

[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Common")]
public void CalculateLineNumbersWithUpperCaseGroupTag()
{
CleanLogFolder();

try
{
//Arrange
using (var hc = new TestHostContext(this))
using (var pagingLogger = new PagingLogger())
{
hc.SetSingleton<IJobServerQueue>(_jobServerQueue.Object);
pagingLogger.Initialize(hc);
Guid timeLineId = Guid.NewGuid();
Guid timeLineRecordId = Guid.NewGuid();
int totalBytes = PagesToWrite * PagingLogger.PageSize;
int logDataSize = System.Text.Encoding.UTF8.GetByteCount(LogDataUpperCaseGroup);

//Act
int bytesSent = 0;
int expectedLines = 0;
// -1 because ##[endgroup] should be ignored since it's not shown in UI and not counted in line numbers
int lineCnt = LogDataUpperCaseGroup.Split('\n').Length - 1;
pagingLogger.Setup(timeLineId, timeLineRecordId);
while (bytesSent < totalBytes)
{
pagingLogger.Write(LogDataUpperCaseGroup);
bytesSent += logDataSize;
expectedLines += lineCnt;
}
pagingLogger.End();

//Assert
_jobServerQueue.Verify(x => x.QueueFileUpload(timeLineId, timeLineRecordId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), true), Times.AtLeast(PagesToWrite));
Assert.Equal(pagingLogger.TotalLines, expectedLines);
}
}
finally
{
//cleanup
CleanLogFolder();
}
}
}
}

0 comments on commit c3e3209

Please sign in to comment.