Skip to content

Commit

Permalink
Format and test fixes (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtmk authored Jan 10, 2024
1 parent 7981db6 commit 55e9532
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
3 changes: 2 additions & 1 deletion sandbox/Example.Core.PublishModel/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using NATS.Client.Serializers.Json;

var subject = "bar.xyz";
var options = NatsOpts.Default with {
var options = NatsOpts.Default with
{
LoggerFactory = LoggerFactory.Create(builder => builder.AddConsole()),
SerializerRegistry = NatsJsonSerializerRegistry.Default,
};
Expand Down
8 changes: 4 additions & 4 deletions src/NATS.Client.Core/NatsConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ public async ValueTask ConnectAsync()
}
}

internal NatsStats GetStats() => Counter.ToStats();

public virtual async ValueTask DisposeAsync()
{
if (!IsDisposed)
Expand Down Expand Up @@ -184,6 +182,8 @@ public virtual async ValueTask DisposeAsync()
}
}

internal NatsStats GetStats() => Counter.ToStats();

internal void EnqueuePing(AsyncPingCommand pingCommand)
{
// Enqueue Ping Command to current working reader.
Expand Down Expand Up @@ -538,7 +538,7 @@ private async void ReconnectLoop()
_currentConnectUri = null;
var urlEnumerator = urls.AsEnumerable().GetEnumerator();
NatsUri? url = null;
CONNECT_AGAIN:
CONNECT_AGAIN:
try
{
if (urlEnumerator.MoveNext())
Expand Down Expand Up @@ -748,7 +748,7 @@ private void EnqueueCommandSync(ICommand command)

private async ValueTask EnqueueCommandAsync(ICommand command)
{
RETRY:
RETRY:
if (_commandWriter.TryWrite(command))
{
Interlocked.Increment(ref Counter.PendingMessages);
Expand Down
8 changes: 6 additions & 2 deletions tests/NATS.Client.Core.Tests/CancellationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ public async Task CommandTimeoutTest()

await using var subConnection = server.CreateClientConnection(NatsOpts.Default with { CommandTimeout = TimeSpan.FromSeconds(1) });
await using var pubConnection = server.CreateClientConnection(NatsOpts.Default with { CommandTimeout = TimeSpan.FromSeconds(1) });

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
var cancellationToken = cts.Token;

await pubConnection.ConnectAsync();

await subConnection.SubscribeCoreAsync<string>("foo");
await subConnection.SubscribeCoreAsync<string>("foo", cancellationToken: cancellationToken);

var cmd = new SleepWriteCommand("PUB foo 5\r\naiueo", TimeSpan.FromSeconds(10));
pubConnection.PostDirectWrite(cmd);

var timeoutException = await Assert.ThrowsAsync<TimeoutException>(async () =>
{
await pubConnection.PublishAsync("foo", "aiueo", opts: new NatsPubOpts { WaitUntilSent = true });
await pubConnection.PublishAsync("foo", "aiueo", opts: new NatsPubOpts { WaitUntilSent = true }, cancellationToken: cancellationToken);
});

timeoutException.Message.Should().Contain("1 seconds elapsing");
Expand Down
4 changes: 2 additions & 2 deletions tests/NATS.Client.Core.Tests/NatsConnectionPoolTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public async Task ConnectionsShouldBeNonDisposable()
}

// Assert
var con2 = (NatsConnection) pool.GetConnection();
var con2 = (NatsConnection)pool.GetConnection();
con2.IsDisposed.Should().BeFalse();
}

Expand All @@ -24,7 +24,7 @@ public async Task ConnectionsShouldBeDisposedWhenPoolIsDisposed()
// Arrange
NatsConnectionPool pool = new(1);

var con = (NatsConnection) pool.GetConnection();
var con = (NatsConnection)pool.GetConnection();

// Act
await pool.DisposeAsync();
Expand Down
8 changes: 7 additions & 1 deletion tests/NATS.Client.Core.Tests/NatsConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Reflection;
using System.Text;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading.Channels;
using Xunit.Sdk;

Expand Down Expand Up @@ -378,6 +379,11 @@ public void InterfaceShouldHaveSamePublicPropertiesEventsAndMethodAsClass()
foreach (var classInfo in classMethods)
{
var name = classInfo.Name;

// TODO: enable this check when we have events pulled up to the interface
if (Regex.IsMatch(name, @"add_|remove_"))
continue;

interfaceMethods.Select(m => m.Name).Should().Contain(name);
}
}
Expand Down Expand Up @@ -432,7 +438,7 @@ public override bool Equals(object? obj)
return false;
}

return Equals((SampleClass) obj);
return Equals((SampleClass)obj);
}

public override int GetHashCode()
Expand Down
2 changes: 1 addition & 1 deletion tests/NATS.Client.KeyValueStore.Tests/GetKeysTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NATS.Client.Core.Tests;
using NATS.Client.Core.Tests;

namespace NATS.Client.KeyValueStore.Tests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Buffers;
using System.Buffers;
using NATS.Client.Core.Tests;
using NATS.Client.Serializers.Json;
using NATS.Client.Services.Internal;
Expand Down

0 comments on commit 55e9532

Please sign in to comment.