Skip to content

Commit

Permalink
Akka.Cluster: added sanity check for Member.AgeComparer (akkadotnet…
Browse files Browse the repository at this point in the history
…#7291)

we would have seen A LOT of smoke and fire if this didn't work correctly, but since we're in the midst of testing for all sorts of member transition-related issues for akkadotnet#6973 we thought it would be best to add a sanity check.
  • Loading branch information
Aaronontheweb authored Jul 22, 2024
1 parent f7f9078 commit 50ef7b9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/core/Akka.Cluster.Tests/MemberOrderingSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,23 @@ public void LeaderOrdering_must_order_members_with_status_joining_exiting_down_l
var shuffled = expected.Shuffle().ToImmutableList();
shuffled.Sort(Member.LeaderStatusOrdering).Should().BeEquivalentTo(expected);
}

[Fact]
public void MemberAgeOrdering_must_order_members_by_ascending_UpNumber()
{
var address = new Address("akka.tcp", "sys1", "host1", 5000);
var m1 = TestMember.Create(address, MemberStatus.Up, ImmutableHashSet<string>.Empty, upNumber: 1);
var m2 = TestMember.Create(address.WithPort(7000), MemberStatus.Up, ImmutableHashSet<string>.Empty, upNumber: 2);
var m3 = TestMember.Create(address.WithPort(3000), MemberStatus.Up, ImmutableHashSet<string>.Empty, upNumber: 3);
var m4 = TestMember.Create(address.WithPort(6000), MemberStatus.Up, ImmutableHashSet<string>.Empty, upNumber: 4);
var m5 = TestMember.Create(address.WithPort(2000), MemberStatus.Up, ImmutableHashSet<string>.Empty, upNumber: 5);

// shuffle the list so the members aren't initially sorted by order
var members = new List<Member>(){ m1, m2, m3, m4, m5 }.Shuffle();
var sortedMembers = ImmutableSortedSet<Member>.Empty.WithComparer(Member.AgeOrdering).Union(members);
sortedMembers.Should().BeEquivalentTo(new List<Member> { m1, m2, m3, m4, m5 });
m1.IsOlderThan(m5).Should().BeTrue();
}
}
}

0 comments on commit 50ef7b9

Please sign in to comment.