From e16ac1a704ff39d2d9f130eef560d74aa945fdbd Mon Sep 17 00:00:00 2001 From: Niklas Petersen <7766483+niklasfp@users.noreply.github.com> Date: Sun, 4 Feb 2024 23:41:25 +0100 Subject: [PATCH] Fix NatsSvcServer start time format so that it's no longer culture aware (#374) Co-authored-by: Niklas Petersen --- src/NATS.Client.Services/NatsSvcServer.cs | 2 +- .../ServicesTests.cs | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/NATS.Client.Services/NatsSvcServer.cs b/src/NATS.Client.Services/NatsSvcServer.cs index a0ad59e51..43dea5c10 100644 --- a/src/NATS.Client.Services/NatsSvcServer.cs +++ b/src/NATS.Client.Services/NatsSvcServer.cs @@ -40,7 +40,7 @@ public NatsSvcServer(NatsConnection nats, NatsSvcConfig config, CancellationToke _cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); _channel = Channel.CreateBounded(32); _taskMsgLoop = Task.Run(MsgLoop); - _started = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); + _started = DateTimeOffset.UtcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffff'Z'"); } /// diff --git a/tests/NATS.Client.Services.Tests/ServicesTests.cs b/tests/NATS.Client.Services.Tests/ServicesTests.cs index 0115ad7d7..d4df7213e 100644 --- a/tests/NATS.Client.Services.Tests/ServicesTests.cs +++ b/tests/NATS.Client.Services.Tests/ServicesTests.cs @@ -1,4 +1,5 @@ using System.Text.Json.Nodes; +using System.Text.RegularExpressions; using NATS.Client.Core.Tests; using NATS.Client.Services.Internal; using NATS.Client.Services.Models; @@ -322,4 +323,31 @@ await s1.AddEndpointAsync( Assert.Equal("999", response.Headers?["Nats-Service-Error-Code"]); Assert.Equal("Missing 'foo' header", response.Headers?["Nats-Service-Error"]); } + + [Fact] + public async Task Service_started_time() + { + var cts = new CancellationTokenSource(TimeSpan.FromSeconds(200)); + var cancellationToken = cts.Token; + + await using var server = NatsServer.Start(); + await using var nats = server.CreateClientConnection(); + var svc = new NatsSvcContext(nats); + + await using var s1 = await svc.AddServiceAsync("s1", "1.0.0", cancellationToken: cancellationToken); + + await s1.AddEndpointAsync( + name: "e1", + handler: async m => + { + await m.ReplyAsync(m.Data, cancellationToken: cancellationToken); + }, + cancellationToken: cancellationToken); + + var stats = s1.GetStats(); + + // Match: 2021-09-01T12:34:56.1234567Z + var formatRegex = new Regex(@"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{7}Z$"); + Assert.Matches(formatRegex, stats.Started); + } }