Skip to content

Commit

Permalink
Port Akka.Tests.Util.Internal tests to async/await - InterlockedSpinT…
Browse files Browse the repository at this point in the history
…ests (#5833)
  • Loading branch information
Arkatufus authored Apr 8, 2022
1 parent 4e7d513 commit 02a178d
Showing 1 changed file with 7 additions and 6 deletions.
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

0 comments on commit 02a178d

Please sign in to comment.