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

Port Akka.Tests.Util.Internal tests to async/await - InterlockedSpinTests #5833

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/core/Akka.Tests/Util/Internal/InterlockedSpinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
using System.Threading.Tasks;
using Akka.TestKit;
using Akka.Util.Internal;
using FluentAssertions.Extensions;
using Xunit;

namespace Akka.Tests.Util.Internal
{
public class InterlockedSpinTests
{
[Fact]
public void When_a_shared_variable_is_updated_on_another_thread_Then_the_update_method_is_rerun()
public async Task When_a_shared_variable_is_updated_on_another_thread_Then_the_update_method_is_rerun()
{
var sharedVariable = "";
var hasEnteredUpdateMethod = new ManualResetEvent(false);
Expand Down Expand Up @@ -55,13 +56,13 @@ public void When_a_shared_variable_is_updated_on_another_thread_Then_the_update_
hasEnteredUpdateMethod.WaitOne(TimeSpan.FromSeconds(2)); //Wait for THREAD 2 to enter updateWhenSignaled
sharedVariable = "-";
okToContinue.Set(); //Signal THREAD 1 it can continue in updateWhenSignaled
task.Wait(TimeSpan.FromSeconds(2)); //Wait for THREAD 1
await task.AwaitWithTimeout(2.Seconds()); //Wait for THREAD 1

sharedVariable.ShouldBe("updated");
numberOfCallsToUpdateWhenSignaled.ShouldBe(2);
}
[Fact]
public void When_a_shared_variable_is_updated_on_another_thread_Then_the_update_method_is_rerun_using_tuples()
public async Task When_a_shared_variable_is_updated_on_another_thread_Then_the_update_method_is_rerun_using_tuples()
{
var sharedVariable = "";
var hasEnteredUpdateMethod = new ManualResetEvent(false);
Expand Down Expand Up @@ -100,14 +101,14 @@ public void When_a_shared_variable_is_updated_on_another_thread_Then_the_update_
hasEnteredUpdateMethod.WaitOne(TimeSpan.FromSeconds(2)); //Wait for THREAD 2 to enter updateWhenSignaled
sharedVariable = "-";
okToContinue.Set(); //Signal THREAD 1 it can continue in updateWhenSignaled
task.Wait(TimeSpan.FromSeconds(2)); //Wait for THREAD 1
await task.AwaitWithTimeout(2.Seconds()); //Wait for THREAD 1

sharedVariable.ShouldBe("updated");
numberOfCallsToUpdateWhenSignaled.ShouldBe(2);
}

[Fact]
public void When_a_shared_variable_is_updated_on_another_thread_Then_the_update_method_is_rerun_but_as_the_break_condition_is_fulfilled_it_do_not_update()
public async Task When_a_shared_variable_is_updated_on_another_thread_Then_the_update_method_is_rerun_but_as_the_break_condition_is_fulfilled_it_do_not_update()
{
var sharedVariable = "";
var hasEnteredUpdateMethod = new ManualResetEvent(false);
Expand Down Expand Up @@ -149,7 +150,7 @@ public void When_a_shared_variable_is_updated_on_another_thread_Then_the_update_
hasEnteredUpdateMethod.WaitOne(TimeSpan.FromSeconds(2));
sharedVariable = "-";
okToContinue.Set();
task.Wait(TimeSpan.FromSeconds(2));
await task.AwaitWithTimeout(2.Seconds());

sharedVariable.ShouldBe("-");
numberOfCallsToUpdateWhenSignaled.ShouldBe(2);
Expand Down