Skip to content

Commit 4559699

Browse files
author
Ruslan Dudchenko
committed
added memory test
1 parent dd8714c commit 4559699

1 file changed

Lines changed: 33 additions & 32 deletions

File tree

ManagedCode.Storage.Tests/StorageBaseTests.cs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
2+
using System.Diagnostics;
33
using System.IO;
44
using System.Linq;
55
using System.Text;
@@ -27,33 +27,34 @@ protected StorageBaseTests()
2727

2828
#region MemoryPayload
2929

30-
//[Fact]
31-
//public async Task WhenBigFilesUpload()
32-
//{
33-
// var directory = Path.Combine(Environment.CurrentDirectory, "managed-code-bucket");
34-
35-
// var bigFiles = new List<LocalFile>()
36-
// {
37-
// GetLocalFile($"{directory}/{nameof(WhenBigFilesUpload)}_1.txt", 100 * 1024 * 1024),
38-
// GetLocalFile($"{directory}/{nameof(WhenBigFilesUpload)}_2.txt", 100 * 1024 * 1024),
39-
// GetLocalFile($"{directory}/{nameof(WhenBigFilesUpload)}_3.txt", 100 * 1024 * 1024)
40-
// };
41-
42-
// foreach (var localFile in bigFiles)
43-
// {
44-
// await Storage.UploadStreamAsync(localFile.FileName, localFile.FileStream);
45-
// }
46-
47-
// //foreach (var localFile in bigFiles)
48-
// //{
49-
// // await Storage.DeleteAsync(localFile.FileName);
50-
// //}
51-
52-
// //foreach (var localFile in bigFiles)
53-
// //{
54-
// // localFile.Dispose();
55-
// //}
56-
//}
30+
[Fact]
31+
public async Task UploadBigFilesAsync()
32+
{
33+
const int fileSize = 70 * 1024 * 1024;
34+
35+
var bigFiles = new List<LocalFile>()
36+
{
37+
GetLocalFile(fileSize),
38+
GetLocalFile(fileSize),
39+
GetLocalFile(fileSize)
40+
};
41+
42+
foreach (var localFile in bigFiles)
43+
{
44+
await Storage.UploadStreamAsync(localFile.FileName, localFile.FileStream);
45+
await localFile.DisposeAsync();
46+
}
47+
48+
Process currentProcess = Process.GetCurrentProcess();
49+
long totalBytesOfMemoryUsed = currentProcess.WorkingSet64;
50+
51+
totalBytesOfMemoryUsed.Should().BeLessThan(3 * fileSize);
52+
53+
foreach (var localFile in bigFiles)
54+
{
55+
await Storage.DeleteAsync(localFile.FileName);
56+
}
57+
}
5758

5859
#endregion
5960

@@ -728,14 +729,14 @@ private async Task<string> DownloadAsync(string fileName)
728729
return await sr.ReadToEndAsync();
729730
}
730731

731-
private LocalFile GetLocalFile(string fileName, int byteSize)
732+
private LocalFile GetLocalFile(int byteSize)
732733
{
733-
var localFile = new LocalFile(fileName);
734+
var localFile = new LocalFile();
734735
var fs = localFile.FileStream;
735736

736737
fs.Seek(byteSize, SeekOrigin.Begin);
737738
fs.WriteByte(0);
738-
fs.Close();
739+
fs.Dispose();
739740

740741
return localFile;
741742
}

0 commit comments

Comments
 (0)