Unit test - have to 'delay' to receive message...

65 views
Skip to first unread message

Wayne Brantley

unread,
Nov 26, 2015, 11:28:15 PM11/26/15
to masstransit-discuss
Using the follow template, if I do not have the Task.Delay(5000) in the test, the YourMessage is never received at the endpoint.
Of course, if I do have the Task.Delay(5000) then I do receive it.   Is there a way to wait for the InMemory bus to 'finish' before stopping it?
(all this done with just setting a simple breakpoint and debugging the unit test)

    [TestFixture]
    public class MassTransitTests
    {
        IBusControl _busControl;

        [SetUp]
        public void Setup()
        {
            _busControl = Bus.Factory.CreateUsingInMemory(cfg =>
            {
                cfg.ReceiveEndpoint("queue_name", ep =>
                {
                    ep.Handler<YourMessage>(context =>
                    {
                        return Console.Out.WriteLineAsync($"Received: {context.Message.Text}");
                    });
                });
            });
            _busControl.Start();
        }

        [TearDown]
        public void TearDown()
        {
            _busControl.Stop(new CancellationTokenSource(Debugger.IsAttached ? TimeSpan.FromMinutes(5) : TimeSpan.FromSeconds(30)).Token);
        }

        [Test]
        public async Task TestMessage()
        {
            await _busControl.Publish(new YourMessage { Text = "Test" });
            await Task.Delay(5000);
        }
    }
    public class YourMessage { public string Text { get; set; } }

Chris Patterson

unread,
Nov 26, 2015, 11:37:28 PM11/26/15
to masstrans...@googlegroups.com
That's something I've been working on. There is a way to monitor activity on the bus that was added but I haven't gone through it closely yet. So I'm not sure how to use it. It will be in the next release. 

__
Chris Patterson




--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/4580c2b9-97fa-4624-81b2-80cdea96bfb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages