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); + } }