Skip to content

Commit 55b230d

Browse files
committed
Cover more branches
1 parent edf8700 commit 55b230d

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/DotNext.Tests/Net/Cluster/Consensus/Raft/MemoryBasedStateMachineTests.cs

+22-7
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public override ValueTask WriteToAsync<TWriter>(TWriter writer, CancellationToke
8080
=> writer.WriteAsync(snapshot, token);
8181
}
8282

83-
internal PersistentStateWithSnapshot(string path, bool useCaching, CompactionMode compactionMode = default)
83+
internal PersistentStateWithSnapshot(string path, bool useCaching, CompactionMode compactionMode = CompactionMode.Sequential)
8484
: base(path, RecordsPerPartition, new Options { UseCaching = useCaching, CompactionMode = compactionMode, IntegrityCheck = true, WriteMode = WriteMode.AutoFlush })
8585
{
8686
}
@@ -625,16 +625,20 @@ public static async Task ClearLog()
625625
}
626626

627627
[Theory]
628-
[InlineData(MemoryBasedStateMachine.CompactionMode.Background)]
629-
[InlineData(MemoryBasedStateMachine.CompactionMode.Foreground)]
630-
[InlineData(MemoryBasedStateMachine.CompactionMode.Sequential)]
631-
[InlineData(MemoryBasedStateMachine.CompactionMode.Incremental)]
632-
public static async Task AppendAndCommitAsync(MemoryBasedStateMachine.CompactionMode compaction)
628+
[InlineData(MemoryBasedStateMachine.CompactionMode.Background, false)]
629+
[InlineData(MemoryBasedStateMachine.CompactionMode.Foreground, false)]
630+
[InlineData(MemoryBasedStateMachine.CompactionMode.Sequential, false)]
631+
[InlineData(MemoryBasedStateMachine.CompactionMode.Incremental, false)]
632+
[InlineData(MemoryBasedStateMachine.CompactionMode.Background, true)]
633+
[InlineData(MemoryBasedStateMachine.CompactionMode.Foreground, true)]
634+
[InlineData(MemoryBasedStateMachine.CompactionMode.Sequential, true)]
635+
[InlineData(MemoryBasedStateMachine.CompactionMode.Incremental, true)]
636+
public static async Task AppendAndCommitAsync(MemoryBasedStateMachine.CompactionMode compaction, bool caching)
633637
{
634638
var entries = new Int64LogEntry[RecordsPerPartition * 2 + 1];
635639
entries.AsSpan().ForEach((ref Int64LogEntry entry, int index) => entry = new Int64LogEntry { Content = 42L + index, Term = index });
636640
var dir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
637-
using var state = new PersistentStateWithSnapshot(dir, true, compaction);
641+
using var state = new PersistentStateWithSnapshot(dir, caching, compaction);
638642
Equal(0L, await state.As<IRaftLog>().AppendAndCommitAsync(new LogEntryList(entries), 1L, false, 0L));
639643
Equal(0L, state.LastCommittedEntryIndex);
640644
Equal(9L, state.LastEntryIndex);
@@ -1079,4 +1083,15 @@ public static async Task EnsureMetadataPersistence()
10791083
await state.As<IRaftLog>().ReadAsync(new LogEntryConsumer(checker), 1L);
10801084
}
10811085
}
1086+
1087+
[Fact]
1088+
public static async Task RegressionIssue244()
1089+
{
1090+
var entries = new Int64LogEntry[RecordsPerPartition + 1];
1091+
entries.AsSpan().ForEach((ref Int64LogEntry entry, int index) => entry = new Int64LogEntry { Content = 42L + index, Term = index });
1092+
var dir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
1093+
using var state = new PersistentStateWithSnapshot(dir, true);
1094+
Equal(0L, await state.As<IRaftLog>().AppendAndCommitAsync(new LogEntryList(entries), 1L, false, entries.Length + 1L));
1095+
Equal(0L, state.LastCommittedEntryIndex);
1096+
}
10821097
}

0 commit comments

Comments
 (0)