|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Diagnostics; |
3 | 3 | using System.IO; |
4 | 4 | using System.Linq; |
5 | 5 | using System.Text; |
@@ -27,33 +27,34 @@ protected StorageBaseTests() |
27 | 27 |
|
28 | 28 | #region MemoryPayload |
29 | 29 |
|
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 | + } |
57 | 58 |
|
58 | 59 | #endregion |
59 | 60 |
|
@@ -627,14 +628,14 @@ private async Task<string> DownloadAsync(string fileName) |
627 | 628 | return await sr.ReadToEndAsync(); |
628 | 629 | } |
629 | 630 |
|
630 | | - private LocalFile GetLocalFile(string fileName, int byteSize) |
| 631 | + private LocalFile GetLocalFile(int byteSize) |
631 | 632 | { |
632 | | - var localFile = new LocalFile(fileName); |
| 633 | + var localFile = new LocalFile(); |
633 | 634 | var fs = localFile.FileStream; |
634 | 635 |
|
635 | 636 | fs.Seek(byteSize, SeekOrigin.Begin); |
636 | 637 | fs.WriteByte(0); |
637 | | - fs.Close(); |
| 638 | + fs.Dispose(); |
638 | 639 |
|
639 | 640 | return localFile; |
640 | 641 | } |
|
0 commit comments