From 7c97c3df21afd6d6b548463dffc58a1d2dccc1e8 Mon Sep 17 00:00:00 2001 From: Ahmed Yasin Koculu Date: Tue, 15 Oct 2024 08:13:34 +0200 Subject: [PATCH] Stabilize replicaiton test case. --- src/ZoneTree.UnitTests/ReplicatorTests.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ZoneTree.UnitTests/ReplicatorTests.cs b/src/ZoneTree.UnitTests/ReplicatorTests.cs index 8ae1fd4..88d85ab 100644 --- a/src/ZoneTree.UnitTests/ReplicatorTests.cs +++ b/src/ZoneTree.UnitTests/ReplicatorTests.cs @@ -4,6 +4,15 @@ namespace Tenray.ZoneTree.UnitTests; public sealed class ReplicatorTests { + [Test] + public void TestReplicator2() + { + for (int i = 0; i < 100; i++) + { + TestReplicator(); + } + } + [Test] public void TestReplicator() { @@ -12,28 +21,25 @@ public void TestReplicator() Directory.Delete(dataPath, true); var recordCount = 50_000; var keyCount = 15_000; - var maxMemory = 10_000; void CreateData() { using var zoneTree = new ZoneTreeFactory() .SetDataDirectory(dataPath + "/source") - .SetMutableSegmentMaxItemCount(maxMemory) .OpenOrCreate(); using var replica = new ZoneTreeFactory() .SetDataDirectory(dataPath + "/replica") - .SetMutableSegmentMaxItemCount(maxMemory) .OpenOrCreate(); using var replicator = new Replicator(replica, dataPath + "/replica-op-index"); using var maintainer1 = zoneTree.CreateMaintainer(); using var maintainer2 = replica.CreateMaintainer(); - var random = new Random(); int replicated = 0; + var k = 0; Parallel.For(0, recordCount, (i) => { var key = i % keyCount; - var value = random.Next(); + var value = Interlocked.Increment(ref k); var opIndex = zoneTree.Upsert(key, value); Task.Run(() => { @@ -60,6 +66,7 @@ void TestEqual() using var iterator1 = zoneTree.CreateIterator(); using var iterator2 = replica.CreateIterator(); + var i = 0; while (true) { var n1 = iterator1.Next(); @@ -67,7 +74,9 @@ void TestEqual() Assert.That(n2, Is.EqualTo(n1)); if (!n1) break; Assert.That(iterator2.Current, Is.EqualTo(iterator1.Current)); + ++i; } + Assert.That(i, Is.EqualTo(keyCount)); zoneTree.Maintenance.Drop(); replica.Maintenance.Drop(); }