* Avoid null endpoint DTO metadata in tests * Enforce console logs hub read permission * Remove unused console logs hub import * Support mapped endpoint metadata in auth tests * Reduce console log capture throughput impact * Address Copilot console logs review * Refactor task scheduling to support tenant-level background work and enhance logging functionality. * Introduce ConsoleStreamHook for stdout/stderr tee and enhance logging validation. Adjust test cases and startup warnings for distributed lock provider usage. * Refactor console logging pipeline with capture optimization and new ConsoleLogsHost; update tests accordingly. * Add Ansi SGR parser for console logs and associated unit tests * Remove ANSI color renderings and parsers; integrate ConsoleLogScopeAccessor for improved logging context with workflow instance ID support. * Address console logs code quality feedback * Address PR review feedback * Preserve console logs extension points * Stabilize console logs host lifecycle * Address final automated review comments * Tighten console log capture shutdown * Address console log review feedback * Address follow-up review feedback * Cover final review feedback * Avoid recursive console provider initialization * Guard console host lease shutdown * Preserve console log scope and provider lifetime * Correlate console log scope fallback * Tighten console scope correlation * Expose host services during provider construction * Redact ANSI-normalized console lines
69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
using Elsa.Diagnostics.ConsoleLogs.Services;
|
|
|
|
namespace Elsa.Diagnostics.ConsoleLogs.UnitTests.Capture;
|
|
|
|
public class ConsoleLineBufferTests
|
|
{
|
|
private readonly ConsoleLineBuffer _buffer = new(Microsoft.Extensions.Options.Options.Create(new ConsoleLogsOptions { MaxLineLength = 5, IdleFlushTimeout = TimeSpan.FromSeconds(1) }));
|
|
|
|
[Fact]
|
|
public void Append_BuffersPartialWritesUntilNewline()
|
|
{
|
|
Assert.Empty(_buffer.Append("hel", DateTimeOffset.UtcNow));
|
|
|
|
var lines = _buffer.Append("lo\n", DateTimeOffset.UtcNow);
|
|
|
|
Assert.Equal(["hello"], lines.Select(x => x.Text));
|
|
}
|
|
|
|
[Fact]
|
|
public void Append_CompletesLineAtMaximumLength()
|
|
{
|
|
var lines = _buffer.Append("hello!", DateTimeOffset.UtcNow);
|
|
|
|
Assert.Equal(["hello"], lines.Select(x => x.Text));
|
|
Assert.Equal("!", _buffer.Flush()?.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void FlushIfIdle_CompletesBufferedLineAfterTimeout()
|
|
{
|
|
var now = DateTimeOffset.UtcNow;
|
|
|
|
_buffer.Append("tail", now);
|
|
|
|
Assert.Null(_buffer.FlushIfIdle(now.AddMilliseconds(500)));
|
|
Assert.Equal("tail", _buffer.FlushIfIdle(now.AddSeconds(2))?.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void Append_PreservesEmptyLinesBetweenWrites()
|
|
{
|
|
var lines = _buffer.Append("a\n\nb\n", DateTimeOffset.UtcNow);
|
|
|
|
Assert.Equal(["a", "", "b"], lines.Select(x => x.Text));
|
|
}
|
|
|
|
[Fact]
|
|
public void Append_PreservesWorkflowInstanceIdAcrossPartialWrites()
|
|
{
|
|
_buffer.Append("hel", DateTimeOffset.UtcNow, "workflow-instance-a");
|
|
|
|
var line = Assert.Single(_buffer.Append("lo\n", DateTimeOffset.UtcNow));
|
|
|
|
Assert.Equal("hello", line.Text);
|
|
Assert.Equal("workflow-instance-a", line.WorkflowInstanceId);
|
|
}
|
|
|
|
[Fact]
|
|
public void Append_DoesNotAssignWorkflowInstanceIdAfterUnscopedPartialWrite()
|
|
{
|
|
_buffer.Append("hel", DateTimeOffset.UtcNow);
|
|
|
|
var line = Assert.Single(_buffer.Append("lo\n", DateTimeOffset.UtcNow, "workflow-instance-a"));
|
|
|
|
Assert.Equal("hello", line.Text);
|
|
Assert.Null(line.WorkflowInstanceId);
|
|
}
|
|
}
|