-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathEnvironment.TickCount.cs
45 lines (42 loc) · 1.46 KB
/
Environment.TickCount.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Xunit;
namespace System.Tests
{
public class EnvironmentTickCount
{
[Fact]
public void TickCountTest()
{
int start = Environment.TickCount;
var times = new HashSet<int>();
Func<bool> test = () =>
{
int time = Environment.TickCount;
times.Add(time);
return time - start > 0;
};
Assert.True(
SpinWait.SpinUntil(test, TimeSpan.FromSeconds(1)) || test(),
$"TickCount did not increase after one second. start: {start}, values tested: {string.Join(", ", times.ToArray())}.");
}
[Fact]
public void TickCount64Test()
{
long start = Environment.TickCount64;
var times = new HashSet<long>();
Func<bool> test = () =>
{
long time = Environment.TickCount64;
times.Add(time);
return time - start > 0;
};
Assert.True(
SpinWait.SpinUntil(test, TimeSpan.FromSeconds(1)) || test(),
$"TickCount did not increase after one second. start: {start}, values tested: {string.Join(", ", times.ToArray())}.");
}
}
}