Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] Update Akka.TestKit to run asynchronous internally. #5609

Closed
Tracked by #5617
Arkatufus opened this issue Feb 8, 2022 · 3 comments
Closed
Tracked by #5617

[TEST] Update Akka.TestKit to run asynchronous internally. #5609

Arkatufus opened this issue Feb 8, 2022 · 3 comments
Labels
akka-testkit Akka.NET Testkit issues
Milestone

Comments

@Arkatufus
Copy link
Contributor

Arkatufus commented Feb 8, 2022

Right now, Akka.TestKit relies on a BlockingQueue internally inside TestState making all test to run async over sync, In order to support full asynchronous test operations, we will need to replace this with something that supports async operation better. The main goal of this spec is to invert all operations into sync over async instead.

The biggest problem right now is the InternalTryReceiveOne() method in the TestKitBase class, it blocks as it waits for a message to get queued into the BlockingQueue<T>. This method gets called by virtually all akka test function that waits for one message or another. This method needs to be converted into an async method.

Options:

  • Wrap InternalTryReceiveOne() inside an async function that uses Task.Run() to spin it in another thread.
private async Task<(bool, MessageEnvelope)> InternalTryReceiveOneAsync(TimeSpan? max, CancellationToken cancellationToken, bool shouldLog)
{
    return await Task.Run(() =>
    {
        var result = InternalTryReceiveOne(out var envelope, max, cancellationToken, shouldLog);
        return (result, envelope);
    }, cancellationToken);
}
  • Replace the internal BlockingQueue<T> implementation with a custom System.Threading.Channels.Channel<T> that supports async read and write
  • Replace the internal BlockingQueue<T> implementation with AsyncEx AsyncCollection or AsyncProducerConsumerQueue
@Arkatufus Arkatufus added the akka-testkit Akka.NET Testkit issues label Feb 8, 2022
@brah-mcdude
Copy link
Contributor

Please let me know if you want me to help. I need this feature more than anyone.

@Arkatufus
Copy link
Contributor Author

Will do, thanks for the offer.

@Arkatufus
Copy link
Contributor Author

All the code are done but can't really be tested until all of the unit tests are converted to the new async code

@Aaronontheweb Aaronontheweb modified the milestones: 1.4.34, 1.4.35 Mar 7, 2022
@Aaronontheweb Aaronontheweb modified the milestones: 1.4.35, 1.5.0 Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
akka-testkit Akka.NET Testkit issues
Projects
No open projects
Development

No branches or pull requests

3 participants