Skip to content

Commit 2e9d764

Browse files
committed
Adds test to capture upload-interrupt node crash.
1 parent fc9249d commit 2e9d764

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

Framework/Utils/Retry.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public void Run()
7171
task();
7272
return;
7373
}
74+
catch (OperationCanceledException)
75+
{
76+
return;
77+
}
7478
catch (Exception ex)
7579
{
7680
var failure = CaptureFailure(ex);

Tests/CodexTests/BasicTests/OneClientTests.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using CodexPlugin;
2+
using FileUtils;
23
using NUnit.Framework;
4+
using System.Diagnostics;
35
using Utils;
46

57
namespace CodexTests.BasicTests
@@ -10,11 +12,47 @@ public class OneClientTests : CodexDistTest
1012
[Test]
1113
public void OneClientTest()
1214
{
13-
var primary = StartCodex();
15+
var node = StartCodex();
1416

15-
PerformOneClientTest(primary);
17+
PerformOneClientTest(node);
1618

17-
LogNodeStatus(primary);
19+
LogNodeStatus(node);
20+
}
21+
22+
[Test]
23+
public void InterruptUploadTest()
24+
{
25+
var tasks = new List<Task<bool>>();
26+
for (var i = 0; i < 10; i++)
27+
{
28+
tasks.Add(Task<bool>.Run(() => RunInterruptUploadTest()));
29+
}
30+
Task.WaitAll(tasks.ToArray());
31+
32+
Assert.That(tasks.Select(t => t.Result).All(r => r == true));
33+
}
34+
35+
private bool RunInterruptUploadTest()
36+
{
37+
var node = StartCodex();
38+
var file = GenerateTestFile(300.MB());
39+
40+
var process = StartCurlUploadProcess(node, file);
41+
42+
Thread.Sleep(500);
43+
process.Kill();
44+
Thread.Sleep(1000);
45+
46+
var log = Ci.DownloadLog(node);
47+
return !log.GetLinesContaining("Unhandled exception in async proc, aborting").Any();
48+
}
49+
50+
private Process StartCurlUploadProcess(ICodexNode node, TrackedFile file)
51+
{
52+
var apiAddress = node.Container.GetAddress(CodexContainerRecipe.ApiPortTag);
53+
var codexUrl = $"{apiAddress}/api/codex/v1/data";
54+
var filePath = file.Filename;
55+
return Process.Start("curl", $"-X POST {codexUrl} -H \"Content-Type: application/octet-stream\" -T {filePath}");
1856
}
1957

2058
private void PerformOneClientTest(ICodexNode primary)

0 commit comments

Comments
 (0)