Skip to content

Commit 1fd5363

Browse files
committed
Fixed a couple flaky tests.
1 parent 634c4fb commit 1fd5363

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/Adaptive.Archiver.IntegrationTests/Helpers/PersistentSubscriptionListener.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616

1717
using System;
18+
using Adaptive.Aeron.Exceptions;
19+
using AeronErrorCode = Adaptive.Aeron.ErrorCode;
1820

1921
namespace Adaptive.Archiver.IntegrationTests.Helpers
2022
{
@@ -23,6 +25,8 @@ internal sealed class PersistentSubscriptionListener : IPersistentSubscriptionLi
2325
public int LiveJoinedCount { get; private set; }
2426
public int LiveLeftCount { get; private set; }
2527
public int ErrorCount { get; private set; }
28+
public int TerminalErrorCount { get; private set; }
29+
public int NonTransientErrorCount { get; private set; }
2630
public Exception LastException { get; private set; }
2731

2832
public void OnLiveJoined() => LiveJoinedCount++;
@@ -32,7 +36,18 @@ internal sealed class PersistentSubscriptionListener : IPersistentSubscriptionLi
3236
public void OnError(Exception e)
3337
{
3438
ErrorCount++;
39+
if (!IsTransient(e))
40+
{
41+
NonTransientErrorCount++;
42+
}
43+
if (e is PersistentSubscriptionException)
44+
{
45+
TerminalErrorCount++;
46+
}
3547
LastException = e;
3648
}
49+
50+
private static bool IsTransient(Exception e) =>
51+
e is RegistrationException re && re.ErrorCode() == AeronErrorCode.RESOURCE_TEMPORARILY_UNAVAILABLE;
3752
}
3853
}

src/Adaptive.Archiver.IntegrationTests/PersistentSubscriptionTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ public void ShouldStartFromStoppedRecordingAndErrorWhenLiveHasAdvanced()
626626
() => Poll(persistentSubscription, fragmentHandler, 1));
627627

628628
Assert.That(fragmentHandler.ReceivedPayloads.Count, Is.EqualTo(recordedMessages.Count));
629-
Assert.That(Listener.ErrorCount, Is.EqualTo(1));
629+
Assert.That(Listener.TerminalErrorCount, Is.EqualTo(1));
630630
Assert.That(Listener.LastException, Is.InstanceOf<PersistentSubscriptionException>());
631631
Assert.That(
632632
((PersistentSubscriptionException)Listener.LastException).ReasonValue,
@@ -1385,8 +1385,8 @@ public void ShouldReplayAndCatchUpWhenExtendedRecordingIsAheadOfLivePosition()
13851385
};
13861386

13871387
// Wait for one AWAIT_LIVE deadline breach.
1388-
Tests.ExecuteUntil(() => Listener.ErrorCount > 0, pollAndTrack, 30_000);
1389-
Assert.That(Listener.ErrorCount, Is.EqualTo(1));
1388+
Tests.ExecuteUntil(() => Listener.NonTransientErrorCount > 0, pollAndTrack, 30_000);
1389+
Assert.That(Listener.NonTransientErrorCount, Is.EqualTo(1));
13901390
Assert.That(persistentSubscription.IsLive, Is.False);
13911391
Assert.That(observedReplaying[0], Is.False);
13921392

@@ -1424,7 +1424,7 @@ public void ShouldReplayAndCatchUpWhenExtendedRecordingIsAheadOfLivePosition()
14241424
AssertPayloads(fragmentHandler.ReceivedPayloads, expected);
14251425
Assert.That(observedReplaying[0], Is.True,
14261426
"PS did not transition through REPLAY/ATTEMPT_SWITCH after revoke");
1427-
Assert.That(Listener.ErrorCount, Is.EqualTo(1));
1427+
Assert.That(Listener.NonTransientErrorCount, Is.EqualTo(1));
14281428
}
14291429

14301430
private void ArmDataDropFromPosition(LossGenController controller, long recordingId, long fromPosition)
@@ -1484,8 +1484,8 @@ public void ShouldRefreshAndReplayWhenLiveAheadOfStopPositionAfterResume()
14841484
};
14851485

14861486
// Wait for one AWAIT_LIVE deadline breach.
1487-
Tests.ExecuteUntil(() => Listener.ErrorCount > 0, pollAndTrack);
1488-
Assert.That(Listener.ErrorCount, Is.EqualTo(1));
1487+
Tests.ExecuteUntil(() => Listener.NonTransientErrorCount > 0, pollAndTrack);
1488+
Assert.That(Listener.NonTransientErrorCount, Is.EqualTo(1));
14891489
Assert.That(
14901490
Listener.LastException.Message,
14911491
Does.Contain("No image became available on the live subscription"));
@@ -1512,7 +1512,7 @@ public void ShouldRefreshAndReplayWhenLiveAheadOfStopPositionAfterResume()
15121512
"PS did not transition through REPLAY/ATTEMPT_SWITCH; refresh path was not exercised");
15131513
Assert.That(Listener.LiveJoinedCount, Is.EqualTo(1));
15141514
Assert.That(Listener.LiveLeftCount, Is.EqualTo(0));
1515-
Assert.That(Listener.ErrorCount, Is.EqualTo(1));
1515+
Assert.That(Listener.NonTransientErrorCount, Is.EqualTo(1));
15161516
}
15171517

15181518
[TestCase(1), TestCase(10), Timeout(20_000)]

0 commit comments

Comments
 (0)