Ejemplo n.º 1
0
    public async Task Test_LockAbandon_MessageFlow()
    {
        await ServiceBusFixture.ServiceBusNamespace.ScorchNamespace();

        using (var ts = new CancellationTokenSource())
            using (var msn = new Messenger(ServiceBusFixture.ConfigSettings.ServiceBusConnectionString, ServiceBusFixture.ConfigSettings.AzureSubscriptionId))
            {
                await msn.Send(new TestMessage());

                msn.Receive <TestMessage>(
                    async m =>
                {
                    await msn.Lock(m);
                    msn.CancelReceive <TestMessage>();
                    await Task.Delay(TimeSpan.FromSeconds(5), ts.Token);
                    await msn.Abandon(m);

                    ts.Cancel(); // kill switch
                });

                try
                {
                    await Task.Delay(TimeSpan.FromMinutes(2), ts.Token);
                }
                catch (TaskCanceledException) { /* soak the kill switch */ }

                ((QueueAdapter <TestMessage>)msn.ServiceBusAdapters[typeof(TestMessage).GetEntityName()]).Messages.Should().BeEmpty();
                ((QueueAdapter <TestMessage>)msn.ServiceBusAdapters[typeof(TestMessage).GetEntityName()]).LockTimers.Should().BeEmpty();
            }
    }