public async Task Should_put_incoming_message_on_error_queue_when_outgoing_is_too_big_WithoutRenewal()
        {
            using var gotCalledFiveTimes = new CountdownEvent(5);

            _activator.Handle <string>(async(innerBus, context, _) =>
            {
                Console.WriteLine($"Got message with ID {context.Headers.GetValue(Headers.MessageId)} - Sending off huge message");

                var hugeMessage = GetHugeMessage();
                await innerBus.SendLocal(hugeMessage);
                gotCalledFiveTimes.Signal();

                Console.WriteLine($"{gotCalledFiveTimes.CurrentCount} tries left");
            });

            _busStarter.Start();

            await _bus.SendLocal("Get going....");

            gotCalledFiveTimes.Wait(TimeSpan.FromSeconds(120));

            //There should now be a message in the error queue.
            _ = await _errorQueueListener.WaitForNextMessage(timeoutSeconds : 5);

            //the error should be logged
            Assert.IsTrue(_listLoggerFactory.Any(l => l.Level == LogLevel.Error));
        }
예제 #2
0
    public async Task ItWorks()
    {
        using var gotMessage = new ManualResetEvent(false);

        _activator.Handle <string>(async(_, context, _) =>
        {
            Console.WriteLine($"Got message with ID {context.Headers.GetValue(Headers.MessageId)} - waiting timeout + 30 secs minutes....");

            await Task.Delay(_visibilityTimeout + TimeSpan.FromSeconds(30));

            Console.WriteLine("done waiting");

            gotMessage.Set();
        });

        _busStarter.Start();

        await _bus.SendLocal("hej med dig min ven!");

        //would appear after visibility timout - if it wasn't  extended
        await Task.Delay(_visibilityTimeout + TimeSpan.FromSeconds(5));


        // see if queue is empty
        using var scope = new RebusTransactionScope();

        var message = await _transport.Receive(scope.TransactionContext, CancellationToken.None);

        await scope.CompleteAsync();

        if (message != null)
        {
            throw new AssertionException(
                      $"Did not expect to receive a message - got one with ID {message.Headers.GetValue(Headers.MessageId)}");
        }

        gotMessage.WaitOrDie(_visibilityTimeout + TimeSpan.FromSeconds(35));

        //make absolutely sure that the transaction has finished
        await Task.Delay(TimeSpan.FromSeconds(10));

        Assert.IsFalse(_listLoggerFactory.Any(l => l.Level == LogLevel.Error), "had an error when handling the message.. check the logs");
    }
예제 #3
0
        public async Task VerifyIt()
        {
            var gotTheMessage = new ManualResetEvent(initialState: false);
            var services      = new ServiceCollection();
            var loggerFactory = new ListLoggerFactory(outputToConsole: true, detailed: true);

            services.AddSingleton(gotTheMessage);

            services.AddScoped <SomethingDisposable>();

            services.AddRebusHandler <StringHandler>();

            services.AddRebus(configure => configure
                              .Logging(l => l.Use(loggerFactory))
                              .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "who cares"))
                              .Options(o => o.Decorate <IPipeline>(c =>
            {
                var pipeline = c.Get <IPipeline>();

                return(new PipelineStepInjector(pipeline)
                       .OnReceive(new MyScopeStep(), PipelineRelativePosition.Before, typeof(DeserializeIncomingMessageStep)));
            })));

            var provider = Using(services.BuildServiceProvider());

            provider.UseRebus();

            await provider.GetRequiredService <IBus>().SendLocal("hej søde ven!");

            gotTheMessage.WaitOrDie(
                timeout: TimeSpan.FromSeconds(3),
                errorMessage: "Message was not received within 3 s timeout, which means that an exception must have occurred somewhere");

            await Task.Delay(TimeSpan.FromSeconds(2));

            var foundWarningOrError = loggerFactory.Any(log => log.Level > LogLevel.Info);

            Assert.That(foundWarningOrError, Is.False,
                        "The log contained one or more warnings/errors, which is an indication that something went wrong when dispatching the message");
        }