public async Task ExceedMaxOpenFiles() { var streams = new List <ManualStream> (); var streamCreated = new ReusableTaskCompletionSource <bool> (); Func <ITorrentFileInfo, FileAccess, ITorrentFileStream> creator = (file, access) => { var s = new ManualStream(file, access); s.WriteTcs = new ReusableTaskCompletionSource <int> (); streams.Add(s); streamCreated.SetResult(true); return(s); }; using var writer = new DiskWriter(creator, 1); var writeTask = writer.WriteAsync(TorrentFile, 0, new byte[100], 0, 100); await streamCreated.Task.WithTimeout(); // There's a limit of 1 concurrent read/write. var secondStreamWaiter = streamCreated.Task.AsTask(); var secondStream = writer.WriteAsync(Others.First(), 0, new byte[100], 0, 100); Assert.ThrowsAsync <TimeoutException> (() => secondStreamWaiter.WithTimeout(100)); streams[0].WriteTcs.SetResult(1); await secondStreamWaiter.WithTimeout(); streams[1].WriteTcs.SetResult(1); await secondStream.WithTimeout(); Assert.IsTrue(streams[0].Disposed); Assert.IsFalse(streams[1].Disposed); }
public async Task CloseFileAsync_Opened() { using var writer = new DiskWriter(); await writer.WriteAsync(TorrentFile, 0, new byte[10], 0, 10); Assert.IsTrue(File.Exists(TorrentFile.FullPath)); Assert.DoesNotThrowAsync(async() => await writer.CloseAsync(TorrentFile)); File.Delete(TorrentFile.FullPath); }
public void CloseFileAsync_Unopened() { using var writer = new DiskWriter(); Assert.DoesNotThrowAsync(async() => await writer.CloseAsync(TorrentFile)); }