Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit e61d48c

Browse files
committed
Speed up tests a bit
1 parent f6826b5 commit e61d48c

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

src/tests/IntegrationTests/Download/DownloadTaskTests.cs

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ namespace IntegrationTests.Download
1212
[TestFixture]
1313
class DownloadTaskTests : BaseTaskManagerTest
1414
{
15-
private const string TestDownload = "http://ipv4.download.thinkbroadband.com/5MB.zip";
16-
private const string TestDownloadMD5 = "b3215c06647bc550406a9c8ccc378756";
17-
1815
public override void OnSetup()
1916
{
2017
base.OnSetup();
@@ -28,35 +25,37 @@ public async Task TestDownloadTask()
2825

2926
var fileSystem = Environment.FileSystem;
3027

31-
var downloadPath = TestBasePath.Combine("5MB.zip");
32-
var downloadHalfPath = TestBasePath.Combine("5MB-split.zip");
28+
var gitLfs = new UriString("https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip");
29+
var gitLfsMd5 = new UriString("https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip.MD5.txt?cb=1");
3330

34-
var downloadTask = new DownloadTask(TaskManager.Token, fileSystem, TestDownload, TestBasePath);
35-
await downloadTask.StartAwait();
31+
var md5 = await new DownloadTextTask(TaskManager.Token, fileSystem, gitLfsMd5, TestBasePath)
32+
.StartAwait();
3633

37-
var downloadPathBytes = fileSystem.ReadAllBytes(downloadPath);
38-
Logger.Trace("File size {0} bytes", downloadPathBytes.Length);
34+
var downloadPath = await new DownloadTask(TaskManager.Token, fileSystem, gitLfs, TestBasePath)
35+
.StartAwait();
3936

4037
var md5Sum = fileSystem.CalculateFileMD5(downloadPath);
41-
md5Sum.Should().Be(TestDownloadMD5);
38+
md5Sum.Should().BeEquivalentTo(md5);
39+
40+
var downloadPathBytes = fileSystem.ReadAllBytes(downloadPath);
41+
Logger.Trace("File size {0} bytes", downloadPathBytes.Length);
4242

4343
var random = new Random();
4444
var takeCount = random.Next(downloadPathBytes.Length);
4545

4646
Logger.Trace("Cutting the first {0} Bytes", downloadPathBytes.Length - takeCount);
4747

4848
var cutDownloadPathBytes = downloadPathBytes.Take(takeCount).ToArray();
49-
fileSystem.WriteAllBytes(downloadHalfPath, cutDownloadPathBytes);
49+
fileSystem.WriteAllBytes(downloadPath, cutDownloadPathBytes);
5050

51-
downloadTask = new DownloadTask(TaskManager.Token, fileSystem, TestDownload,
52-
TestBasePath, validationHash: TestDownloadMD5);
53-
await downloadTask.StartAwait();
51+
downloadPath = await new DownloadTask(TaskManager.Token, fileSystem, gitLfs, TestBasePath)
52+
.StartAwait();
5453

55-
var downloadHalfPathBytes = fileSystem.ReadAllBytes(downloadHalfPath);
54+
var downloadHalfPathBytes = fileSystem.ReadAllBytes(downloadPath);
5655
Logger.Trace("File size {0} Bytes", downloadHalfPathBytes.Length);
5756

5857
md5Sum = fileSystem.CalculateFileMD5(downloadPath);
59-
md5Sum.Should().Be(TestDownloadMD5);
58+
md5Sum.Should().BeEquivalentTo(md5);
6059
}
6160

6261
[Test]
@@ -134,38 +133,21 @@ public void TestDownloadFileAndHash()
134133

135134
var fileSystem = Environment.FileSystem;
136135

137-
var gitArchivePath = TestBasePath.Combine("git.zip");
138-
var gitLfsArchivePath = TestBasePath.Combine("git-lfs.zip");
139-
140-
var downloadGitMd5Task = new DownloadTextTask(TaskManager.Token, fileSystem,
141-
"https://ghfvs-installer.github.com/unity/portable_git/git.zip.MD5.txt?cb=1",
142-
TestBasePath);
143-
144-
var downloadGitTask = new DownloadTask(TaskManager.Token, fileSystem,
145-
"https://ghfvs-installer.github.com/unity/portable_git/git.zip",
146-
TestBasePath);
136+
var gitLfs = new UriString("https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip");
137+
var gitLfsMd5 = new UriString("https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip.MD5.txt?cb=1");
147138

148139
var downloadGitLfsMd5Task = new DownloadTextTask(TaskManager.Token, fileSystem,
149-
"https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip.MD5.txt?cb=1",
150-
TestBasePath);
151-
140+
gitLfsMd5, TestBasePath);
152141

153142
var downloadGitLfsTask = new DownloadTask(TaskManager.Token, fileSystem,
154-
"https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip",
155-
TestBasePath);
143+
gitLfs, TestBasePath);
156144

157145
var result = true;
158146
Exception exception = null;
159147

160148
var autoResetEvent = new AutoResetEvent(false);
161149

162-
downloadGitMd5Task
163-
.Then((b, s) =>
164-
{
165-
downloadGitTask.ValidationHash = s;
166-
})
167-
.Then(downloadGitTask)
168-
.Then(downloadGitLfsMd5Task)
150+
downloadGitLfsMd5Task
169151
.Then((b, s) =>
170152
{
171153
downloadGitLfsTask.ValidationHash = s;
@@ -214,8 +196,7 @@ public void TestDownloadShutdownTimeWhenInterrupted()
214196
})
215197
.Progress(p =>
216198
{
217-
if (p.Percentage > 0.2)
218-
evtStop.Set();
199+
evtStop.Set();
219200
});
220201

221202
downloadGitTask.Start();

0 commit comments

Comments
 (0)