Skip to content

Commit 6128fd6

Browse files
filzrevtimcassell
andauthored
chore: Add retry and increase timeout for dotMemory/dotTrace tests (#2971)
* chore: add retry and increase timeout for dotMemory/dotTrace tests * Update src/BenchmarkDotNet.Diagnostics.dotMemory/DotMemoryDiagnoser.cs * Update src/BenchmarkDotNet.Diagnostics.dotTrace/DotTraceDiagnoser.cs --------- Co-authored-by: Tim Cassell <cassell.timothy@gmail.com>
1 parent 25914b8 commit 6128fd6

3 files changed

Lines changed: 48 additions & 14 deletions

File tree

src/BenchmarkDotNet.Diagnostics.dotMemory/DotMemoryDiagnoser.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DotMemoryDiagnoser(Uri? nugetUrl = null, string? downloadTo = null)
1414

1515
protected override void InitTool(Progress progress)
1616
{
17-
DotMemory.InitAsync(progress, nugetUrl, NuGetApi.V3, downloadTo).Wait();
17+
DotMemory.InitAsync(progress, nugetUrl, NuGetApi.V3, downloadTo).GetAwaiter().GetResult();
1818
}
1919

2020
protected override void AttachToCurrentProcess(string snapshotFile)
@@ -24,7 +24,11 @@ protected override void AttachToCurrentProcess(string snapshotFile)
2424

2525
protected override void AttachToProcessByPid(int pid, string snapshotFile)
2626
{
27-
DotMemory.Attach(new DotMemory.Config().ProfileExternalProcess(pid).SaveToFile(snapshotFile));
27+
var config = new DotMemory.Config()
28+
.UseCustomResponseTimeout(milliseconds:60 * 1000)
29+
.ProfileExternalProcess(pid)
30+
.SaveToFile(snapshotFile);
31+
DotMemory.Attach(config);
2832
}
2933

3034
protected override void TakeSnapshot()

src/BenchmarkDotNet.Diagnostics.dotTrace/DotTraceDiagnoser.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DotTraceDiagnoser(Uri? nugetUrl = null, string? downloadTo = null)
1414

1515
protected override void InitTool(Progress progress)
1616
{
17-
DotTrace.InitAsync(progress, nugetUrl, NuGetApi.V3, downloadTo).Wait();
17+
DotTrace.InitAsync(progress, nugetUrl, NuGetApi.V3, downloadTo).GetAwaiter().GetResult();
1818
}
1919

2020
protected override void AttachToCurrentProcess(string snapshotFile)
@@ -25,7 +25,11 @@ protected override void AttachToCurrentProcess(string snapshotFile)
2525

2626
protected override void AttachToProcessByPid(int pid, string snapshotFile)
2727
{
28-
DotTrace.Attach(new DotTrace.Config().ProfileExternalProcess(pid).SaveToFile(snapshotFile));
28+
var config = new DotTrace.Config()
29+
.UseCustomResponseTimeout(milliseconds: 60 * 1000)
30+
.ProfileExternalProcess(pid)
31+
.SaveToFile(snapshotFile);
32+
DotTrace.Attach(config);
2933
DotTrace.StartCollectingData();
3034
}
3135

src/BenchmarkDotNet/Diagnosers/SnapshotProfilerBase.cs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Collections.Immutable;
4-
using System.Diagnostics;
5-
using System.IO;
6-
using System.Linq;
71
using BenchmarkDotNet.Analysers;
82
using BenchmarkDotNet.Engines;
93
using BenchmarkDotNet.Exporters;
@@ -12,6 +6,13 @@
126
using BenchmarkDotNet.Reports;
137
using BenchmarkDotNet.Running;
148
using BenchmarkDotNet.Validators;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.Collections.Immutable;
12+
using System.Diagnostics;
13+
using System.IO;
14+
using System.Linq;
15+
using System.Threading;
1516

1617
#nullable enable
1718

@@ -89,17 +90,42 @@ public void DisplayResults(ILogger logger)
8990

9091
private void Init(ILogger logger)
9192
{
93+
logger.WriteLineInfo($"Ensuring that {ShortName} prerequisite is installed...");
94+
var progress = new Progress(logger, $"Installing {ShortName}");
95+
96+
const int MaxRetries = 5;
97+
int retryCount = 0;
98+
99+
Retry:
92100
try
93101
{
94-
logger.WriteLineInfo($"Ensuring that {ShortName} prerequisite is installed...");
95-
var progress = new Progress(logger, $"Installing {ShortName}");
96102
InitTool(progress);
103+
97104
logger.WriteLineInfo($"{ShortName} prerequisite is installed");
98105
logger.WriteLineInfo($"{ShortName} runner path: {GetRunnerPath()}");
106+
return;
99107
}
100-
catch (Exception e)
108+
catch (OperationCanceledException ex)
101109
{
102-
logger.WriteLineError(e.ToString());
110+
logger.WriteLineError(ex.ToString());
111+
return;
112+
}
113+
// Following exceptions are expected to be thrown.
114+
// https://github.com/JetBrains/profiler-self-api/blob/02f8410d26c184cb50ddaead6fcce89d7f34517c/JetBrains.Profiler.SelfApi/src/Impl/PrerequisiteBase.cs#L188-L202
115+
catch (Exception ex)
116+
{
117+
if (retryCount >= MaxRetries)
118+
{
119+
logger.WriteLineError(ex.ToString());
120+
return;
121+
}
122+
123+
var delaySeconds = retryCount * retryCount;
124+
logger.WriteLineWarning($"InitTool failed with exception: {ex.Message}");
125+
logger.WriteLineWarning($"Retry {retryCount + 1}/{MaxRetries} after {delaySeconds} seconds..."); // Retry after seconds (0, 1, 4, 9, 16)
126+
Thread.Sleep(TimeSpan.FromSeconds(delaySeconds));
127+
++retryCount;
128+
goto Retry;
103129
}
104130
}
105131

0 commit comments

Comments
 (0)