Skip to content

Commit 2853441

Browse files
committed
fixed: FakeClock value changes must be atomic
1 parent d86cc06 commit 2853441

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixed
66
- fixed LambdaCommandBusExtensions return values
7+
- fixed: FakeClock value changes must be atomic
78

89
### Changed
910

Revo.Testing/Core/FakeClock.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ namespace Revo.Testing.Core
66
{
77
public static class FakeClock
88
{
9-
private static readonly AsyncLocal<FakeClockImpl> ClockLocal = new AsyncLocal<FakeClockImpl>();
10-
private static readonly object SetupLock = new object();
9+
private static readonly AsyncLocal<FakeClockImpl> ClockLocal = new();
10+
private static readonly object SetupLock = new();
1111

1212
public static DateTimeOffset Now
1313
{
14-
get { return Clock.Now; }
15-
set { Clock.Now = value; }
14+
get => Clock.Now;
15+
set => Clock.Now = value;
1616
}
1717

1818
private static FakeClockImpl Clock
@@ -30,21 +30,33 @@ private static FakeClockImpl Clock
3030

3131
public static void Setup()
3232
{
33+
Now = DateTimeOffset.Now;
34+
3335
lock (SetupLock)
3436
{
3537
if (!(Revo.Core.Core.Clock.Current is FakeClockImpl))
3638
{
3739
Revo.Core.Core.Clock.SetClock(() => Clock);
3840
}
3941
}
40-
41-
Now = DateTimeOffset.Now;
4242
}
4343

4444
public class FakeClockImpl : IClock
4545
{
46-
public DateTimeOffset Now { get; set; }
46+
private DateTimeOffsetBoxed boxed = new(DateTimeOffset.Now);
47+
48+
public DateTimeOffset Now
49+
{
50+
get => boxed.Value;
51+
set => boxed = new DateTimeOffsetBoxed(value);
52+
}
53+
4754
public DateTimeOffset UtcNow => Now.ToUniversalTime();
4855
}
56+
57+
private class DateTimeOffsetBoxed(DateTimeOffset value)
58+
{
59+
public DateTimeOffset Value { get; } = value;
60+
}
4961
}
5062
}

0 commit comments

Comments
 (0)