From ae4fd616389ec4463cf0ff9d03c2064e5ff5a462 Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Fri, 8 Apr 2022 17:44:45 +0700 Subject: [PATCH] Port Akka.Tests.Util.Internal tests to async/await - InterlockedSpinTests --- .../Util/Internal/InterlockedSpinTests.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/Akka.Tests/Util/Internal/InterlockedSpinTests.cs b/src/core/Akka.Tests/Util/Internal/InterlockedSpinTests.cs index 424a7361eed..5480319bd15 100644 --- a/src/core/Akka.Tests/Util/Internal/InterlockedSpinTests.cs +++ b/src/core/Akka.Tests/Util/Internal/InterlockedSpinTests.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Akka.TestKit; using Akka.Util.Internal; +using FluentAssertions.Extensions; using Xunit; namespace Akka.Tests.Util.Internal @@ -17,7 +18,7 @@ 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); @@ -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); @@ -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); @@ -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);