mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-18 05:37:59 +00:00
Logged .NET events with the time they happened (#1042)
This commit is contained in:
1 parent
ca6ad6b1f0
commit
4616d1a4b2
12 files changed
+354
-17
No files matched your search
@@ -0,0 +1,48 @@
|
||||
using System.Globalization;
|
||||
|
||||
using AIStudio.Tools;
|
||||
|
||||
namespace AIStudio.Tests.Tools;
|
||||
|
||||
/// <summary>
|
||||
/// Pins the format in which log events travel to the Rust runtime.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The Rust runtime reads this format to log each event with the time it happened. Its tests in
|
||||
/// runtime/src/log.rs parse the same text, so both sides have to change together.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class TerminalLoggerTests
|
||||
{
|
||||
private const string TRANSPORT_TIMESTAMP = "2026-10-09T17:53:54.5629130+00:00";
|
||||
|
||||
private static readonly DateTimeOffset EVENT_TIME = new DateTimeOffset(2026, 10, 9, 17, 53, 54, TimeSpan.Zero).AddTicks(5_629_130);
|
||||
|
||||
[Test]
|
||||
public void TheTransportTimestampIsPinned()
|
||||
{
|
||||
Assert.That(TerminalLogger.FormatTransportTimestamp(EVENT_TIME), Is.EqualTo(TRANSPORT_TIMESTAMP));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheTransportTimestampIgnoresTheCurrentCulture()
|
||||
{
|
||||
var culture = (CultureInfo)CultureInfo.InvariantCulture.Clone();
|
||||
culture.DateTimeFormat.TimeSeparator = ".";
|
||||
|
||||
var previousCulture = CultureInfo.CurrentCulture;
|
||||
try
|
||||
{
|
||||
CultureInfo.CurrentCulture = culture;
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(EVENT_TIME.ToString("yyyy-MM-dd HH:mm:ss.fff"), Is.EqualTo("2026-10-09 17.53.54.562"), "The format sent before followed the time separator of the current culture.");
|
||||
Assert.That(TerminalLogger.FormatTransportTimestamp(EVENT_TIME), Is.EqualTo(TRANSPORT_TIMESTAMP));
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
CultureInfo.CurrentCulture = previousCulture;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user