Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions Obvs.NetMQ.Tests/TestPublishSubscribe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Obvs.NetMQ.Tests
{
// Each test uses its own port, clear of the ranges TestServiceBusWithNetMq binds,
// because xUnit runs test classes in parallel
public class TestPublishSubscribe
{
[Fact, Trait("Category", "Explicit")]
Expand All @@ -29,7 +31,7 @@ public async Task TestSendingAndReceivingStringsOverLocalHost()

}, err => Console.WriteLine("Error: " + err));

IMessageSource<IMessage> source = new MessageSource<IMessage>("tcp://localhost:5556",
IMessageSource<IMessage> source = new MessageSource<IMessage>("tcp://localhost:5560",
new IMessageDeserializer<IMessage>[]
{
new JsonMessageDeserializer<TestMessage1>(),
Expand All @@ -39,7 +41,7 @@ public async Task TestSendingAndReceivingStringsOverLocalHost()

var sub = source.Messages.Subscribe(observer);

IMessagePublisher<IMessage> publisher = new MessagePublisher<IMessage>("tcp://localhost:5556",
IMessagePublisher<IMessage> publisher = new MessagePublisher<IMessage>("tcp://localhost:5560",
new JsonMessageSerializer(), topic);

await publisher.PublishAsync(new TestMessage1 { Id = 1 });
Expand All @@ -50,16 +52,17 @@ public async Task TestSendingAndReceivingStringsOverLocalHost()
await publisher.PublishAsync(new TestMessage2 { Id = 3 });
await Task.Delay(TimeSpan.FromSeconds(2));

sub.Dispose();
source.Dispose();
publisher.Dispose();

Assert.True(messages.OfType<TestMessage1>().Any(msg => msg.Id == 1), "TestMessage1 1 not received");
Assert.True(messages.OfType<TestMessage1>().Any(msg => msg.Id == 2), "TestMessage1 2 not received");
Assert.True(messages.OfType<TestMessage1>().Any(msg => msg.Id == 3), "TestMessage1 3 not received");

Assert.True(messages.OfType<TestMessage2>().Any(msg => msg.Id == 1), "TestMessage2 1 not received");
Assert.True(messages.OfType<TestMessage2>().Any(msg => msg.Id == 2), "TestMessage2 2 not received");
Assert.True(messages.OfType<TestMessage2>().Any(msg => msg.Id == 3), "TestMessage2 3 not received");

sub.Dispose();
source.Dispose();
}

[Fact, Trait("Category", "Explicit")]
Expand All @@ -76,7 +79,7 @@ public async Task TestSendingAndReceivingBytesOverLocalHost()

}, err => Console.WriteLine("Error: " + err));

IMessageSource<IMessage> source = new MessageSource<IMessage>("tcp://localhost:5556",
IMessageSource<IMessage> source = new MessageSource<IMessage>("tcp://localhost:5561",
new IMessageDeserializer<IMessage>[]
{
new ProtoBufMessageDeserializer<TestMessage1>(),
Expand All @@ -86,7 +89,7 @@ public async Task TestSendingAndReceivingBytesOverLocalHost()

var sub = source.Messages.Subscribe(observer);

IMessagePublisher<IMessage> publisher = new MessagePublisher<IMessage>("tcp://localhost:5556",
IMessagePublisher<IMessage> publisher = new MessagePublisher<IMessage>("tcp://localhost:5561",
new ProtoBufMessageSerializer(), topic);

await publisher.PublishAsync(new TestMessage1 { Id = 1 });
Expand All @@ -97,16 +100,17 @@ public async Task TestSendingAndReceivingBytesOverLocalHost()
await publisher.PublishAsync(new TestMessage2 { Id = 3 });
await Task.Delay(TimeSpan.FromSeconds(2));

sub.Dispose();
source.Dispose();
publisher.Dispose();

Assert.True(messages.OfType<TestMessage1>().Any(msg => msg.Id == 1), "TestMessage1 1 not received");
Assert.True(messages.OfType<TestMessage1>().Any(msg => msg.Id == 2), "TestMessage1 2 not received");
Assert.True(messages.OfType<TestMessage1>().Any(msg => msg.Id == 3), "TestMessage1 3 not received");

Assert.True(messages.OfType<TestMessage2>().Any(msg => msg.Id == 1), "TestMessage2 1 not received");
Assert.True(messages.OfType<TestMessage2>().Any(msg => msg.Id == 2), "TestMessage2 2 not received");
Assert.True(messages.OfType<TestMessage2>().Any(msg => msg.Id == 3), "TestMessage2 3 not received");

sub.Dispose();
source.Dispose();
}

[Fact, Trait("Category", "Explicit")]
Expand All @@ -117,8 +121,10 @@ public async Task TestMessagesLongerThan32Characters()

const string topic = "TestTopicxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
IDisposable sub;
MessageSource<IMessage> source;
MessagePublisher<IMessage> publisher;
{
var source = new MessageSource<IMessage>("tcp://localhost:5557",
source = new MessageSource<IMessage>("tcp://localhost:5562",
new IMessageDeserializer<IMessage>[]
{
new ProtoBufMessageDeserializer<TestMessageWhereTypeIsVeryMuchDefinitionLongerThen32Characters>(),
Expand All @@ -134,7 +140,7 @@ public async Task TestMessagesLongerThan32Characters()
}

{
var publisher = new MessagePublisher<IMessage>("tcp://localhost:5557",
publisher = new MessagePublisher<IMessage>("tcp://localhost:5562",
new ProtoBufMessageSerializer(),
topic);

Expand All @@ -150,6 +156,8 @@ await publisher.PublishAsync(new TestMessageWhereTypeIsVeryMuchDefinitionLongerT
await Task.Delay(TimeSpan.FromSeconds(2));

sub.Dispose();
source.Dispose();
publisher.Dispose();
}

[ProtoContract]
Expand Down
5 changes: 5 additions & 0 deletions Obvs.NetMQ.Tests/TestServiceBusWithNetMq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ public async Task TestServiceEndpointsOverLocalHostSockets()
// wait some time until we think all messages have been sent and received
await Task.Delay(TimeSpan.FromSeconds(3));

// dispose before asserting, so a failed assertion doesn't leave sockets bound for other tests
((IDisposable)serviceBus).Dispose();
((IDisposable)serviceBusClient1).Dispose();
((IDisposable)serviceBusClient2).Dispose();

// test we got everything we expected
Assert.True(messages.OfType<TestCommand1>().Count() == 2, "TestCommand1");
Assert.True(messages.OfType<TestEvent1>().Count() == 4, "TestEvent1");
Expand Down
Loading