Esempio n. 1
0
        public async Task PauseResumeHashingMode()
        {
            var pieceHashed = new TaskCompletionSource <object> ();

            Manager.PieceHashed += (o, e) => pieceHashed.TrySetResult(null);

            var mode = new HashingMode(Manager, DiskManager, ConnectionManager, Settings);

            Manager.Mode = mode;

            var pausedEvent = Manager.WaitForState(TorrentState.HashingPaused);

            mode.Pause();
            await pausedEvent.WithTimeout("#pause");

            Assert.AreEqual(TorrentState.HashingPaused, mode.State, "#a");

            var hashingTask = mode.WaitForHashingToComplete();
            await Task.Delay(50);

            Assert.IsFalse(pieceHashed.Task.IsCompleted, "#1");

            var resumeEvent = Manager.WaitForState(TorrentState.Hashing);

            mode.Resume();
            await resumeEvent.WithTimeout("#resume");

            Assert.AreEqual(pieceHashed.Task, await Task.WhenAny(pieceHashed.Task, Task.Delay(1000)), "#2");
            Assert.AreEqual(TorrentState.Hashing, mode.State, "#b");
        }
Esempio n. 2
0
        public async Task StopWhileHashing()
        {
            var mode = new HashingMode(Manager, DiskManager, ConnectionManager, Settings);

            Manager.Mode = mode;
            mode.Pause();

            var hashingTask = mode.WaitForHashingToComplete();
            await Manager.StopAsync();

            Assert.ThrowsAsync <TaskCanceledException> (() => hashingTask, "#1");
            Assert.AreEqual(Manager.State, TorrentState.Stopped, "#2");
        }
Esempio n. 3
0
        public void CancelHashing()
        {
            var mode = new HashingMode(Manager, DiskManager, ConnectionManager, Settings);

            Manager.Mode = mode;
            mode.Pause();

            var hashingTask = mode.WaitForHashingToComplete();
            var stoppedMode = new StoppedMode(Manager, DiskManager, ConnectionManager, Settings);

            Manager.Mode = stoppedMode;

            // Ensure the hashing mode ends and does not throw exceptions.
            Assert.ThrowsAsync <TaskCanceledException> (() => hashingTask, "#1");
            Assert.AreSame(stoppedMode, Manager.Mode, "#2");
        }