Skip to content

Commit e1caefd

Browse files
authored
Simplify PerfStressUtilities.Sleep() (Azure#17028)
1 parent 690cc68 commit e1caefd

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

common/PerfStressShared/PerfStressUtilities.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
using CommandLine;
55
using System;
66
using System.Collections.Generic;
7-
using System.Diagnostics;
87
using System.Linq;
98
using System.Reflection;
109
using System.Reflection.Emit;
1110
using System.Text.RegularExpressions;
1211
using System.Threading;
12+
using System.Threading.Tasks;
1313

1414
namespace Azure.Test.PerfStress
1515
{
@@ -83,9 +83,9 @@ internal static Thread PrintStatus(string header, Func<object> status, bool newL
8383
{
8484
try
8585
{
86-
Sleep(TimeSpan.FromSeconds(intervalSeconds), token);
86+
Task.Delay(TimeSpan.FromSeconds(intervalSeconds), token).Wait();
8787
}
88-
catch (OperationCanceledException)
88+
catch (Exception e) when (ContainsOperationCanceledException(e))
8989
{
9090
}
9191

@@ -114,20 +114,5 @@ internal static Thread PrintStatus(string header, Func<object> status, bool newL
114114

115115
return thread;
116116
}
117-
118-
internal static void Sleep(TimeSpan timeout, CancellationToken token)
119-
{
120-
var sw = Stopwatch.StartNew();
121-
while (sw.Elapsed < timeout)
122-
{
123-
if (token.IsCancellationRequested)
124-
{
125-
// Simulate behavior of Task.Delay(TimeSpan, CancellationToken)
126-
throw new OperationCanceledException();
127-
}
128-
129-
Thread.Sleep(TimeSpan.FromMilliseconds(10));
130-
}
131-
}
132117
}
133118
}

sdk/template/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pr:
1919
paths:
2020
include:
2121
- common/Perf/
22+
- common/PerfStressShared/
2223
- common/Stress/
2324
- sdk/template/
2425

0 commit comments

Comments
 (0)