public async Task FileSystemLock_VerifyMessageFromSettings() { using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); settings.FeedLockMessage = "FROMSETTINGS!!"; var lockMessage = Guid.NewGuid().ToString(); await InitCommand.RunAsync(settings, fileSystem, log); var lockObj = await SourceUtility.VerifyInitAndLock(settings, fileSystem, lockMessage, log, CancellationToken.None); lockObj.IsLocked.Should().BeTrue(); var path = Path.Combine(target.Root, ".lock"); var json = JObject.Parse(File.ReadAllText(path)); json["message"].ToString().Should().Be("FROMSETTINGS!!"); json["date"].ToString().Should().NotBeNullOrEmpty(); json["pid"].ToString().Should().NotBeNullOrEmpty(); } }
public async Task FileSystem_VerifyFileSystemResetOnLock() { using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem1 = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var lockMessage = Guid.NewGuid().ToString(); await InitCommand.RunAsync(settings, fileSystem1, log); // Verify that files work normally var testFile = fileSystem1.Get("test.json"); await testFile.GetJsonOrNull(log, CancellationToken.None); var testFile2 = fileSystem1.Get("test2.json"); fileSystem1.Files.Count.Should().BeGreaterThan(1); // Lock the feed to reset it var lockObj1 = await SourceUtility.VerifyInitAndLock(settings, fileSystem1, lockMessage, log, CancellationToken.None); lockObj1.IsLocked.Should().BeTrue(); // 1 file should be found since it loads the index fileSystem1.Files.Count.Should().Be(1); InvalidOperationException failureEx = null; try { // Verify the old file no longer works await testFile.GetJsonOrNull(log, CancellationToken.None); await testFile2.GetJsonOrNull(log, CancellationToken.None); } catch (InvalidOperationException ex) { failureEx = ex; } failureEx.Should().NotBeNull(); } }
public async Task FileSystemLock_VerifyMessageShownInLog() { using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var log2 = new TestLogger(); var fileSystem1 = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var fileSystem2 = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var lockMessage = Guid.NewGuid().ToString(); await InitCommand.RunAsync(settings, fileSystem1, log); var lockObj1 = await SourceUtility.VerifyInitAndLock(settings, fileSystem1, lockMessage, log, CancellationToken.None); lockObj1.IsLocked.Should().BeTrue(); var lockObj2Task = Task.Run(async() => await SourceUtility.VerifyInitAndLock(settings, fileSystem2, lockMessage, log2, CancellationToken.None)); while (!log2.GetMessages().Contains($"Feed is locked by: {lockMessage}")) { await Task.Delay(10); } lockObj1.Release(); var lockObj2 = await lockObj2Task; while (!lockObj2.IsLocked) { await Task.Delay(10); } lockObj1.IsLocked.Should().BeFalse(); lockObj2.IsLocked.Should().BeTrue(); } }