2016-02-14 16:55:32 +00:00
|
|
|
using System;
|
2019-07-10 03:14:53 +00:00
|
|
|
using System.Collections.Generic;
|
2016-02-14 16:55:32 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2019-07-10 03:14:53 +00:00
|
|
|
using System.Threading;
|
2016-02-14 16:55:32 +00:00
|
|
|
using FluentAssertions;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
using NzbDrone.Core.Download;
|
|
|
|
using NzbDrone.Core.Download.Clients.Blackhole;
|
2019-07-10 03:14:53 +00:00
|
|
|
using NzbDrone.Core.MediaFiles;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
using NzbDrone.Test.Common;
|
2016-02-14 16:55:32 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class ScanWatchFolderFixture : CoreTest<ScanWatchFolder>
|
|
|
|
{
|
2017-03-06 21:23:25 +00:00
|
|
|
protected readonly string _title = "Droned.1998.1080p.WEB-DL-DRONE";
|
2016-02-14 16:55:32 +00:00
|
|
|
protected string _completedDownloadFolder = @"c:\blackhole\completed".AsOsAgnostic();
|
2019-07-10 03:14:53 +00:00
|
|
|
|
2016-02-14 16:55:32 +00:00
|
|
|
protected void GivenCompletedItem()
|
|
|
|
{
|
|
|
|
var targetDir = Path.Combine(_completedDownloadFolder, _title);
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
.Setup(c => c.GetDirectories(_completedDownloadFolder))
|
|
|
|
.Returns(new[] { targetDir });
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
.Setup(c => c.GetFiles(targetDir, SearchOption.AllDirectories))
|
|
|
|
.Returns(new[] { Path.Combine(targetDir, "somefile.mkv") });
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
.Setup(c => c.GetFileSize(It.IsAny<string>()))
|
|
|
|
.Returns(1000000);
|
2019-07-10 03:14:53 +00:00
|
|
|
|
2020-09-05 05:23:24 +00:00
|
|
|
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
|
2020-07-02 03:19:38 +00:00
|
|
|
.Returns<string, IEnumerable<string>, bool>((b, s, e) => s.ToList());
|
2016-02-14 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void GivenChangedItem()
|
|
|
|
{
|
|
|
|
var currentSize = Mocker.GetMock<IDiskProvider>().Object.GetFileSize("abc");
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
.Setup(c => c.GetFileSize(It.IsAny<string>()))
|
|
|
|
.Returns(currentSize + 1);
|
|
|
|
}
|
2019-07-10 03:14:53 +00:00
|
|
|
|
2016-02-14 16:55:32 +00:00
|
|
|
private void VerifySingleItem(DownloadItemStatus status)
|
|
|
|
{
|
|
|
|
var items = Subject.GetItems(_completedDownloadFolder, TimeSpan.FromMilliseconds(50)).ToList();
|
|
|
|
|
|
|
|
items.Count.Should().Be(1);
|
|
|
|
items.First().Status.Should().Be(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetItems_should_considered_locked_files_queued()
|
|
|
|
{
|
|
|
|
GivenCompletedItem();
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
.Setup(c => c.IsFileLocked(It.IsAny<string>()))
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
Thread.Sleep(60);
|
|
|
|
|
|
|
|
VerifySingleItem(DownloadItemStatus.Downloading);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetItems_should_considered_changing_files_queued()
|
|
|
|
{
|
|
|
|
GivenCompletedItem();
|
|
|
|
|
|
|
|
VerifySingleItem(DownloadItemStatus.Downloading);
|
|
|
|
|
|
|
|
// If we keep changing the file every 20ms we should stay Downloading.
|
2023-05-23 10:52:39 +00:00
|
|
|
for (var i = 0; i < 10; i++)
|
2016-02-14 16:55:32 +00:00
|
|
|
{
|
|
|
|
TestLogger.Info("Iteration {0}", i);
|
|
|
|
|
|
|
|
GivenChangedItem();
|
|
|
|
|
|
|
|
VerifySingleItem(DownloadItemStatus.Downloading);
|
|
|
|
|
|
|
|
Thread.Sleep(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Until it remains unchanged for >=50ms.
|
|
|
|
Thread.Sleep(60);
|
|
|
|
|
|
|
|
VerifySingleItem(DownloadItemStatus.Completed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|