Test Process Crash

21 views
Skip to first unread message

Namik Baris Idil

unread,
May 19, 2021, 8:59:18 PM5/19/21
to masstransit-discuss
Hello All,

For unit testing purposes, instead of forcing the current executing thread to sleep or wait for a message, I wrap the message retrieving code into the Polly. You can find a sample code to check the published messages below:

var messages = await RetryAndWait.SelectAsync(
_ => _busTestHarness.Published.SelectAsync<TMessage>(
BusCancellationToken)
.Select(m => m.Context.Message), expectedPublishedMessageCount, delayBeforeRead, retryCount)
.ToListAsync();

return messages.ToArray();

This is working perfectly most of the time but sometimes, test process crashing and ending whole testing pipeline (and if it is deploying, whole process). Here is the error I am getting:


The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.
        at MassTransit.Testing.AsyncMessageListExtensions.Select[TElement,TResult](IAsyncEnumerable`1 elements)+MoveNext()
        at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
     --- End of stack trace from previous location where exception was thrown ---
        at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread)
        at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.InvokeContinuation()
        at MassTransit.Testing.MessageObservers.AsyncElementList`1.SelectAsync(FilterDelegate`1 filter, CancellationToken cancellationToken)+MoveNext()
        at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
     --- End of stack trace from previous location where exception was thrown ---
        at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread)
        at System.Threading.ThreadPoolWorkQueue.Dispatch()


What is wrong here? Logic seems OK but for some reason it sometimes crashing.


Note: 

* BusCancellation token is basically a cancellation token with 1 second timeout.
* RetryAndWait is a wrapper for Polly
* I do not know if it is directly related but it is happening more frequently on Jenkins pipeline compared to local test runs.

I’d really appreciate any help or suggestions.

Best,

Barish

Chris Patterson

unread,
May 20, 2021, 9:55:32 AM5/20/21
to masstrans...@googlegroups.com
Not a clue, good luck.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/9B8F9746-BF13-4491-9284-0839C9D4E3F2%40popcore.com.
Reply all
Reply to author
Forward
0 new messages