Skip to content

Commit f29fc92

Browse files
author
Ruslan Dudchenko
committed
Merge branch 'memory-test' into remove-comment
2 parents 5ba6820 + 4559699 commit f29fc92

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

@@ -627,14 +628,14 @@ private async Task<string> DownloadAsync(string fileName)
627628
return await sr.ReadToEndAsync();
628629
}
629630

630-
private LocalFile GetLocalFile(string fileName, int byteSize)
631+
private LocalFile GetLocalFile(int byteSize)
631632
{
632-
var localFile = new LocalFile(fileName);
633+
var localFile = new LocalFile();
633634
var fs = localFile.FileStream;
634635

635636
fs.Seek(byteSize, SeekOrigin.Begin);
636637
fs.WriteByte(0);
637-
fs.Close();
638+
fs.Dispose();
638639

639640
return localFile;
640641
}

0 commit comments

Comments
 (0)