Skip to content

Commit e111702

Browse files
authored
Convert Akka.Remote.Tests to async - Remove AkkaSpec dependency (#5900)
* Convert Akka.Remote.Tests to async - Remove AkkaSpec dependency * Attempt to fix AkkaProtocolSpec racy spec - Make sure that volatile is accessed correctly - Make sure that Heartbeat() is called before value check * Fix racy condition
1 parent c079d6c commit e111702

File tree

6 files changed

+18
-23
lines changed

6 files changed

+18
-23
lines changed

src/core/Akka.Remote.Tests/AccrualFailureDetectorSpec.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
using System;
99
using System.Collections.Generic;
1010
using System.Linq;
11-
using Akka.TestKit;
1211
using Akka.Util.Internal;
1312
using Xunit;
1413

1514
namespace Akka.Remote.Tests
1615
{
1716

18-
public class AccrualFailureDetectorSpec : AkkaSpec
17+
public class AccrualFailureDetectorSpec
1918
{
2019
public static IEnumerable<(T, T)> Slide<T>(IEnumerable<T> values)
2120
{

src/core/Akka.Remote.Tests/AckedDeliverySpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace Akka.Remote.Tests
1717
{
1818

19-
public class AckedDeliverySpec : AkkaSpec
19+
public class AckedDeliverySpec
2020
{
2121
sealed class Sequenced : IHasSequenceNumber
2222
{

src/core/Akka.Remote.Tests/DeadlineFailureDetectorSpec.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
using System;
99
using System.Collections.Generic;
1010
using System.Linq;
11-
using Akka.TestKit;
1211
using FluentAssertions;
1312
using FluentAssertions.Extensions;
1413
using Xunit;
1514

1615
namespace Akka.Remote.Tests
1716
{
18-
public class DeadlineFailureDetectorSpec : AkkaSpec
17+
public class DeadlineFailureDetectorSpec
1918
{
2019
[Fact]
2120
public void DeadlineFailureDetector_must_mark_node_as_monitored_after_a_series_of_successful_heartbeats()

src/core/Akka.Remote.Tests/FailureDetectorRegistrySpec.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88
using System;
99
using System.Collections.Generic;
10-
using Akka.TestKit;
1110
using Xunit;
1211

1312
namespace Akka.Remote.Tests
1413
{
1514

16-
public class FailureDetectorRegistrySpec : AkkaSpec
15+
public class FailureDetectorRegistrySpec
1716
{
1817
[Fact]
1918
public void FailureDetectorRegistry_must_mark_node_as_available_after_a_series_of_successful_heartbeats()

src/core/Akka.Remote.Tests/Transport/AkkaProtocolSpec.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,18 @@ private Collaborators GetCollaborators()
117117
private class TestFailureDetector : FailureDetector
118118
{
119119
#pragma warning disable CS0420
120-
// ReSharper disable once InconsistentNaming
121-
internal volatile bool isAvailable = true;
122-
public override bool IsAvailable => Volatile.Read(ref isAvailable);
123-
124-
// ReSharper disable once InconsistentNaming
125-
internal volatile bool called;
126-
public override bool IsMonitoring => Volatile.Read(ref called);
127-
#pragma warning restore CS0420
120+
private volatile bool _isAvailable = true;
121+
public override bool IsAvailable => Volatile.Read(ref _isAvailable);
122+
public void SetAvailable(bool available) => Volatile.Write(ref _isAvailable, available);
123+
124+
private volatile bool _called;
125+
public override bool IsMonitoring => Volatile.Read(ref _called);
128126

129127
public override void HeartBeat()
130128
{
131-
called = true;
129+
Volatile.Write(ref _called, true);
132130
}
131+
#pragma warning restore CS0420
133132
}
134133

135134
private readonly Config _config;
@@ -167,7 +166,7 @@ public async Task ProtocolStateActor_must_in_inbound_mode_accept_payload_after_A
167166

168167
reader.Tell(TestAssociate(33), TestActor);
169168

170-
await AwaitConditionAsync(() => collaborators.FailureDetector.called, DefaultTimeout);
169+
await AwaitConditionAsync(() => collaborators.FailureDetector.IsMonitoring, DefaultTimeout);
171170

172171
var wrappedHandle = await ExpectMsgOfAsync(DefaultTimeout, "expected InboundAssociation", o =>
173172
{
@@ -181,7 +180,7 @@ public async Task ProtocolStateActor_must_in_inbound_mode_accept_payload_after_A
181180

182181
wrappedHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(TestActor));
183182

184-
Assert.True(collaborators.FailureDetector.called);
183+
Assert.True(collaborators.FailureDetector.IsMonitoring);
185184

186185
// Heartbeat was sent in response to Associate
187186
await AwaitConditionAsync(() => LastActivityIsHeartbeat(collaborators.Registry), DefaultTimeout);
@@ -236,7 +235,8 @@ public async Task ProtocolStateActor_must_in_outbound_mode_delay_readiness_until
236235
failureDetector: collaborators.FailureDetector));
237236

238237
await AwaitConditionAsync(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout);
239-
Assert.True(collaborators.FailureDetector.called);
238+
239+
await AwaitConditionAsync(() => collaborators.FailureDetector.IsMonitoring, DefaultTimeout);
240240

241241
//keeps sending heartbeats
242242
await AwaitConditionAsync(() => LastActivityIsHeartbeat(collaborators.Registry), DefaultTimeout);
@@ -393,9 +393,7 @@ public async Task ProtocolStateActor_must_disassociate_when_failure_detector_sig
393393
//wait for one heartbeat
394394
await AwaitConditionAsync(() => LastActivityIsHeartbeat(collaborators.Registry), DefaultTimeout);
395395

396-
#pragma warning disable CS0420
397-
Volatile.Write(ref collaborators.FailureDetector.isAvailable, false);
398-
#pragma warning restore CS0420
396+
collaborators.FailureDetector.SetAvailable(false);
399397

400398
await ExpectMsgOfAsync("expected Disassociated(DisassociateInfo.Unknown", o =>
401399
{

src/core/Akka.Remote.Tests/Transport/ThrottleModeSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace Akka.Remote.Tests.Transport
1616
{
17-
public class ThrottleModeSpec : AkkaSpec
17+
public class ThrottleModeSpec
1818
{
1919
static readonly long HalfSecond = TimeSpan.FromSeconds(0.5).Ticks.ToNanos();
2020

0 commit comments

Comments
 (0)