Skip to content

Commit 243d1fe

Browse files
committed
Test fixes for the removal of non-batched buffered log processing
1 parent 775f0f9 commit 243d1fe

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

src/WebJobs.Script.WebHost/Diagnostics/ConsoleWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class ConsoleWriter : IDisposable
2020
// we can influence the latency distribution by controlling how much of the buffer we will process in one pass.
2121
// If we set this to 1, the P50 latency will be low, but the P99 latency will be high.
2222
// If we set this to a large value, it keeps the P99 latency under control but the P50 degrades.
23-
// In local testing with a console attached, processing 1/10th of the buffer size per iteration yields single digit P50 while keeping P99 under 100ms.
23+
// In local testing with a console attached, processing 1/10th of the buffer size per iteration yields P50 under 10ms with P99 under 100ms.
2424
private const int SingleWriteBufferDenominator = 10;
2525

2626
private static readonly TimeSpan DisposeTimeout = TimeSpan.FromSeconds(5);

test/WebJobs.Script.Tests/Diagnostics/LinuxContainerEventGeneratorWithConsoleOutputTests.cs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void Dispose()
3535
Console.SetOut(standardOutput);
3636
}
3737

38-
private IEnvironment CreateEnvironment(bool consoleDisabled = false, int? bufferSize = null, bool? batched = null)
38+
private IEnvironment CreateEnvironment(bool consoleDisabled = false, int? bufferSize = null)
3939
{
4040
var mockEnvironment = new Mock<IEnvironment>(MockBehavior.Strict);
4141
mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.ContainerName)).Returns(_containerName);
@@ -45,13 +45,6 @@ private IEnvironment CreateEnvironment(bool consoleDisabled = false, int? buffer
4545

4646
mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.ConsoleLoggingDisabled)).Returns(consoleDisabled ? "1" : "0");
4747
mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.ConsoleLoggingBufferSize)).Returns(bufferSize?.ToString());
48-
mockEnvironment.Setup(p => p.GetEnvironmentVariable(EnvironmentSettingNames.ConsoleLoggingBufferBatched)).Returns(
49-
batched switch
50-
{
51-
null => null,
52-
true => "1",
53-
false => "0",
54-
});
5548
return mockEnvironment.Object;
5649
}
5750

@@ -86,12 +79,10 @@ public void SingleEventNoBuffer()
8679
Assert.Equal($"MS_FUNCTION_LOGS 4,C37E3412-86D1-4B93-BC5A-A2AE09D26C2D,TestApp,TestFunction,TestEvent,TestSource,\"These are the details, lots of details\",\"This is the summary, a great summary\",{ScriptHost.Version},{timestamp.ToString("O")},TestExceptionType,\"Test exception message, with details\",E2D5A6ED-4CE3-4CFD-8878-FD4814F0A1F3,3AD41658-1C4E-4C9D-B0B9-24F2BDAE2829,F0AAA9AD-C3A6-48B9-A75E-57BB280EBB53,TEST-CONTAINER,test-stamp,test-tenant,TestRuntimeSiteName,TestSlotName", output);
8780
}
8881

89-
[Theory]
90-
[InlineData(false)]
91-
[InlineData(true)]
92-
public async Task SingleEventBuffer(bool batched)
82+
[Fact]
83+
public async Task SingleEventBuffer()
9384
{
94-
var env = CreateEnvironment(bufferSize: 10, batched: batched);
85+
var env = CreateEnvironment(bufferSize: 10);
9586
var generator = new LinuxContainerEventGenerator(env);
9687

9788
var timestamp = DateTime.Parse("2023-04-19T14:12:00.0000000Z");
@@ -105,12 +96,10 @@ public async Task SingleEventBuffer(bool batched)
10596
Assert.Equal($"MS_FUNCTION_LOGS 4,C37E3412-86D1-4B93-BC5A-A2AE09D26C2D,TestApp,TestFunction,TestEvent,TestSource,\"These are the details, lots of details\",\"This is the summary, a great summary\",{ScriptHost.Version},{timestamp.ToString("O")},TestExceptionType,\"Test exception message, with details\",E2D5A6ED-4CE3-4CFD-8878-FD4814F0A1F3,3AD41658-1C4E-4C9D-B0B9-24F2BDAE2829,F0AAA9AD-C3A6-48B9-A75E-57BB280EBB53,TEST-CONTAINER,test-stamp,test-tenant,TestRuntimeSiteName,TestSlotName", output);
10697
}
10798

108-
[Theory]
109-
[InlineData(false)]
110-
[InlineData(true)]
111-
public async Task MultipleEventsBuffered(bool batched)
99+
[Fact]
100+
public async Task MultipleEventsBuffered()
112101
{
113-
var env = CreateEnvironment(bufferSize: 10, batched: batched);
102+
var env = CreateEnvironment(bufferSize: 10);
114103
var generator = new LinuxContainerEventGenerator(env);
115104

116105
var timestamp = DateTime.Parse("2023-04-19T14:12:00.0000000Z");
@@ -130,13 +119,11 @@ public async Task MultipleEventsBuffered(bool batched)
130119
Assert.Equal($"MS_FUNCTION_LOGS 4,C37E3412-86D1-4B93-BC5A-A2AE09D26C2D,TestApp,TestFunction3,TestEvent,TestSource,\"These are the details, lots of details\",\"This is the summary, a great summary\",{ScriptHost.Version},{timestamp.ToString("O")},TestExceptionType,\"Test exception message, with details\",E2D5A6ED-4CE3-4CFD-8878-FD4814F0A1F3,3AD41658-1C4E-4C9D-B0B9-24F2BDAE2829,F0AAA9AD-C3A6-48B9-A75E-57BB280EBB53,TEST-CONTAINER,test-stamp,test-tenant,TestRuntimeSiteName,TestSlotName", output[2]);
131120
}
132121

133-
[Theory]
134-
[InlineData(false)]
135-
[InlineData(true)]
136-
public void MultipleEventsWithTinyBuffer_WritesDirectlyToConsoleOnTimeout(bool batched)
122+
[Fact]
123+
public void MultipleEventsWithTinyBuffer_WritesDirectlyToConsoleOnTimeout()
137124
{
138125
// setup in a state where the buffer isn't being processed and can only hold two messages
139-
var env = CreateEnvironment(bufferSize: 2, batched: batched);
126+
var env = CreateEnvironment(bufferSize: 2);
140127
var consoleWriter = new ConsoleWriter(env, LinuxContainerEventGenerator.LogUnhandledException, consoleBufferTimeout: TimeSpan.FromMilliseconds(10), autoStart: false);
141128
var generator = new LinuxContainerEventGenerator(env, consoleWriter);
142129

@@ -160,7 +147,7 @@ public void MultipleEventsWithTinyBuffer_WritesDirectlyToConsoleOnTimeout(bool b
160147
public async Task WritesLogsDirectlyWhenBufferIsFull()
161148
{
162149
// setup in a state where the buffer isn't being processed and can only hold two messages
163-
var env = CreateEnvironment(bufferSize: 2, batched: true);
150+
var env = CreateEnvironment(bufferSize: 2);
164151
var consoleWriter = new ConsoleWriter(env, LinuxContainerEventGenerator.LogUnhandledException, consoleBufferTimeout: TimeSpan.FromMilliseconds(500), autoStart: false);
165152
var generator = new LinuxContainerEventGenerator(env, consoleWriter);
166153

@@ -172,7 +159,7 @@ public async Task WritesLogsDirectlyWhenBufferIsFull()
172159
generator.LogFunctionTraceEvent(LogLevel.Information, "C37E3412-86D1-4B93-BC5A-A2AE09D26C2D", "TestApp", "TestFunction3", "TestEvent", "TestSource", "These are the details, lots of details", "This is the summary, a great summary", "TestExceptionType", "Test exception message, with details", "E2D5A6ED-4CE3-4CFD-8878-FD4814F0A1F3", "3AD41658-1C4E-4C9D-B0B9-24F2BDAE2829", "F0AAA9AD-C3A6-48B9-A75E-57BB280EBB53", "TestRuntimeSiteName", "TestSlotName", timestamp);
173160
await Task.Delay(TimeSpan.FromMilliseconds(10));
174161

175-
consoleWriter.StartProcessingBuffer(batched: true);
162+
consoleWriter.StartProcessingBuffer();
176163
await Task.Delay(TimeSpan.FromMilliseconds(50));
177164

178165
using var sr = new StreamReader(_consoleOut);
@@ -190,7 +177,7 @@ public async Task WritesLogsDirectlyWhenBufferIsFull()
190177
[Fact]
191178
public async Task FlushesBufferOnDispose()
192179
{
193-
var env = CreateEnvironment(bufferSize: 10, batched: true);
180+
var env = CreateEnvironment(bufferSize: 10);
194181
var consoleWriter = new ConsoleWriter(env, LinuxContainerEventGenerator.LogUnhandledException, consoleBufferTimeout: TimeSpan.FromMilliseconds(500), autoStart: true);
195182
var generator = new LinuxContainerEventGenerator(env, consoleWriter);
196183

0 commit comments

Comments
 (0)