feat(batch11): complete filestore init feature and test port
This commit is contained in:
@@ -81,6 +81,59 @@ public sealed partial class ConcurrencyTests1
|
||||
});
|
||||
}
|
||||
|
||||
[Fact] // T:2427
|
||||
public void NoRaceJetStreamFileStoreKeyFileCleanup_ShouldSucceed()
|
||||
{
|
||||
WithStore((_, root) =>
|
||||
{
|
||||
var msgDir = Path.Combine(root, FileStoreDefaults.MsgDir);
|
||||
Directory.CreateDirectory(msgDir);
|
||||
var perm = UnixFileMode.UserRead | UnixFileMode.UserWrite;
|
||||
|
||||
var errors = new ConcurrentQueue<Exception>();
|
||||
Parallel.For(0, 300, i =>
|
||||
{
|
||||
var payload = BitConverter.GetBytes(i);
|
||||
var keyFile = Path.Combine(msgDir, string.Format(FileStoreDefaults.KeyScan, (uint)(i + 1)));
|
||||
var err = JetStreamFileStore.WriteAtomically(keyFile, payload, perm, sync: true);
|
||||
if (err != null)
|
||||
errors.Enqueue(err);
|
||||
});
|
||||
|
||||
errors.ShouldBeEmpty();
|
||||
var keyFiles = Directory.GetFiles(msgDir, "*.key");
|
||||
keyFiles.Length.ShouldBe(300);
|
||||
|
||||
foreach (var key in keyFiles.Skip(1))
|
||||
File.Delete(key);
|
||||
|
||||
Directory.GetFiles(msgDir, "*.key").Length.ShouldBe(1);
|
||||
Directory.GetFiles(msgDir, "*.tmp").ShouldBeEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact] // T:2447
|
||||
public void NoRaceEncodeConsumerStateBug_ShouldSucceed()
|
||||
{
|
||||
for (var i = 0; i < 5_000; i++)
|
||||
{
|
||||
var pending = new Pending
|
||||
{
|
||||
Sequence = 1,
|
||||
Timestamp = DateTimeOffset.UtcNow.AddSeconds(1).ToUnixTimeSeconds() * 1_000_000_000L,
|
||||
};
|
||||
var state = new ConsumerState
|
||||
{
|
||||
Delivered = new SequencePair { Consumer = 1, Stream = 1 },
|
||||
Pending = new Dictionary<ulong, Pending> { [1] = pending },
|
||||
};
|
||||
|
||||
var encoded = StoreParity.EncodeConsumerState(state);
|
||||
var (_, err) = JetStreamFileStore.DecodeConsumerState(encoded);
|
||||
err.ShouldBeNull();
|
||||
}
|
||||
}
|
||||
|
||||
private static void WithStore(Action<JetStreamFileStore, string> action, StreamConfig? cfg = null)
|
||||
{
|
||||
var root = NewRoot();
|
||||
|
||||
Reference in New Issue
Block a user