Skip to content

Commit

Permalink
Fix NatsSvcServer start time format so that it's no longer culture aw…
Browse files Browse the repository at this point in the history
…are (#374)

Co-authored-by: Niklas Petersen <[email protected]>
  • Loading branch information
niklasfp and niklasfp authored Feb 4, 2024
1 parent d267959 commit e16ac1a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/NATS.Client.Services/NatsSvcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public NatsSvcServer(NatsConnection nats, NatsSvcConfig config, CancellationToke
_cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
_channel = Channel.CreateBounded<SvcMsg>(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'");
}

/// <summary>
Expand Down
28 changes: 28 additions & 0 deletions tests/NATS.Client.Services.Tests/ServicesTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -322,4 +323,31 @@ await s1.AddEndpointAsync<int>(
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<int>(
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);
}
}

0 comments on commit e16ac1a

Please sign in to comment.