Skip to content

Commit

Permalink
added big file download with memory limitation test
Browse files Browse the repository at this point in the history
  • Loading branch information
bezzad committed Dec 3, 2023
1 parent e99d7fd commit 422166e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
35 changes: 34 additions & 1 deletion src/Downloader.Test/IntegrationTests/DownloadIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Downloader.Test.IntegrationTests;

public abstract class DownloadIntegrationTest
public abstract class DownloadIntegrationTest : IDisposable
{
private readonly ITestOutputHelper _output;
protected string URL { get; set; }
Expand All @@ -29,6 +29,12 @@ public DownloadIntegrationTest(ITestOutputHelper output)
URL = DummyFileHelper.GetFileWithNameUrl(Filename, DummyFileHelper.FileSize16Kb);
}

public void Dispose()
{
if (File.Exists(FilePath))
File.Delete(FilePath);
}

protected void DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
if (e.Error is not null)
Expand Down Expand Up @@ -839,4 +845,31 @@ public async Task DownloadBigFileOnMemory()
Assert.Equal(100.0, Downloader.Package.SaveProgress);
Assert.True(actualFile.AreEqual(stream));
}

[Fact]
public async Task DownloadBigFileWithMemoryLimitationOnDisk()
{
// arrange
var totalSize = 1024 * 1024 * 1024; // 1GB
//Downloader.AddLogger(new FileLogger($"D:\\TestDownload\\DownloadBigFileOnDisk_{DateTime.Now.ToString("yyyyMMdd.HHmmss")}.log"));
byte fillByte = 123;
Config.ChunkCount = 16;
Config.ParallelCount = 16;
Config.MaximumBytesPerSecond = 0;
Config.MaximumMemoryBufferBytes = 1024 * 1024 * 100; // 100MB
URL = DummyFileHelper.GetFileWithNameUrl(Filename, totalSize, fillByte);

// act
await Downloader.DownloadFileTaskAsync(URL, FilePath);
using var fileStream = File.Open(FilePath, FileMode.Open, FileAccess.Read);

// assert
Assert.Equal(totalSize, Downloader.Package.TotalFileSize);
Assert.Equal(totalSize, fileStream.Length);
Assert.Equal(100.0, Downloader.Package.SaveProgress);
for (int i = 0; i < totalSize; i++)
{
Assert.Equal(fillByte, fileStream.ReadByte());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Downloader.Test.Helper;
using Xunit.Abstractions;
using Xunit.Abstractions;

namespace Downloader.Test.IntegrationTests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Downloader.Test.Helper;
using Xunit.Abstractions;
using Xunit.Abstractions;

namespace Downloader.Test.IntegrationTests;

Expand All @@ -17,5 +16,5 @@ public SerialDownloadIntegrationTest(ITestOutputHelper output) : base(output)

Downloader = new DownloadService(Config);
Downloader.DownloadFileCompleted += DownloadFileCompleted;
}
}
}

0 comments on commit 422166e

Please sign in to comment.