Skip to content

Commit ab4c755

Browse files
committed
PR feedback.
- Moved using statements outside of namespaces in SentryDatabaseLogging.cs and SentryCountdownLock.cs. Specified preference for this in .editorconfig. - Renamed _init back to Init in SentryDatabaseLogging.cs. - Moved type aliases in InterlockedBoolean.cs and InterlockedBooleanTests.cs outside of the namespace and changed them from built-in type names to explicit references to the underlying types. - Made _value in InterlockedBoolean private and added an internal test-specific property instead. - Added MethodImpl hints to the methods it InterlockedBoolean.cs requesting aggressive inlining. - Changed parameters to the implicit conversion operatons in InterlockedBoolean from _this to @this. - Standardized .Should.Be(..) assertions in InterlockedBooleanTests.cs so that the expectation is always named expected.
1 parent 0141420 commit ab4c755

File tree

5 files changed

+42
-29
lines changed

5 files changed

+42
-29
lines changed

src/Sentry.Azure.Functions.Worker/.editorconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
# Reason: Azure Functions worker doesn't set SynchronizationContext but Durable Functions does and required affinity.
44
# (https://github.com/Azure/azure-functions-dotnet-worker/issues/1520)
5-
dotnet_diagnostic.CA2007.severity = none
5+
dotnet_diagnostic.CA2007.severity = none
6+
7+
dotnet_style_namespace_declaration_with_usings_placement = prefer_outside_namespace

src/Sentry.EntityFramework/SentryDatabaseLogging.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
namespace Sentry.EntityFramework;
2-
31
using Sentry.Internal;
42

3+
namespace Sentry.EntityFramework;
4+
55
/// <summary>
66
/// Sentry Database Logger
77
/// </summary>
88
internal static class SentryDatabaseLogging
99
{
10-
private static InterlockedBoolean _init;
10+
private static InterlockedBoolean Init;
1111

1212
internal static SentryCommandInterceptor? UseBreadcrumbs(
1313
IQueryLogger? queryLogger = null,
1414
bool initOnce = true,
1515
IDiagnosticLogger? diagnosticLogger = null)
1616
{
17-
if (initOnce && _init.Exchange(true))
17+
if (initOnce && Init.Exchange(true))
1818
{
1919
diagnosticLogger?.LogWarning("{0}.{1} was already executed.",
2020
nameof(SentryDatabaseLogging), nameof(UseBreadcrumbs));

src/Sentry/Internal/InterlockedBoolean.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
namespace Sentry.Internal;
2-
31
#if NET9_0_OR_GREATER
4-
using TBool = bool;
2+
using TBool = System.Boolean;
53
#else
6-
using TBool = int;
4+
using TBool = System.Int32;
75
#endif
86

7+
namespace Sentry.Internal;
8+
99
internal struct InterlockedBoolean
1010
{
11-
internal volatile TBool _value;
11+
private volatile TBool _value;
12+
13+
[Browsable(false)]
14+
internal TBool ValueForTests => _value;
1215

1316
#if NET9_0_OR_GREATER
1417
private const TBool True = true;
@@ -20,11 +23,15 @@ internal struct InterlockedBoolean
2023

2124
public InterlockedBoolean() { }
2225

26+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2327
public InterlockedBoolean(bool value) { _value = value ? True : False; }
2428

25-
public static implicit operator bool(InterlockedBoolean? _this) => (_this != null) && (_this.Value._value != False);
26-
public static implicit operator InterlockedBoolean(bool _this) => new InterlockedBoolean(_this);
29+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
30+
public static implicit operator bool(InterlockedBoolean @this) => (@this._value != False);
31+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
32+
public static implicit operator InterlockedBoolean(bool @this) => new InterlockedBoolean(@this);
2733

34+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2835
public bool Exchange(bool newValue)
2936
{
3037
TBool localNewValue = newValue ? True : False;
@@ -34,6 +41,7 @@ public bool Exchange(bool newValue)
3441
return (localReturnValue != False);
3542
}
3643

44+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3745
public bool CompareExchange(bool value, bool comparand)
3846
{
3947
TBool localValue = value ? True : False;

src/Sentry/Threading/ScopedCountdownLock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
namespace Sentry.Threading;
2-
31
using Sentry.Internal;
42

3+
namespace Sentry.Threading;
4+
55
/// <summary>
66
/// A synchronization primitive that tracks the amount of <see cref="CounterScope"/>s held,
77
/// and is signaled when the count reaches zero while a <see cref="LockScope"/> is held.

test/Sentry.Tests/Internals/InterlockedBooleanTests.cs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
namespace Sentry.Tests.Internals;
2-
31
#if NET9_0_OR_GREATER
4-
using TBool = bool;
2+
using TBool = System.Boolean;
53
#else
6-
using TBool = int;
4+
using TBool = System.Int32;
75
#endif
86

7+
namespace Sentry.Tests.Internals;
8+
99
public class InterlockedBooleanTests
1010
{
1111
#if NET9_0_OR_GREATER
@@ -25,13 +25,13 @@ public class InterlockedBooleanTests
2525
public void InterlockedBoolean_Constructor_ConstructsExpected(bool value)
2626
{
2727
// Arrange
28-
var tboolValue = ToTBool(value);
28+
var expected = ToTBool(value);
2929

3030
// Act
3131
var actual = new InterlockedBoolean(value);
3232

3333
// Assert
34-
actual._value.Should().Be(tboolValue);
34+
actual.ValueForTests.Should().Be(expected);
3535
}
3636

3737
[Theory]
@@ -41,12 +41,13 @@ public void InterlockedBoolean_ImplicitToBool_ReturnsExpected(bool value)
4141
{
4242
// Arrange
4343
var sut = new InterlockedBoolean(value);
44+
var expected = value;
4445

4546
// Act
4647
bool actual = sut;
4748

4849
// Assert
49-
actual.Should().Be(value);
50+
actual.Should().Be(expected);
5051
}
5152

5253
[Theory]
@@ -55,13 +56,13 @@ public void InterlockedBoolean_ImplicitToBool_ReturnsExpected(bool value)
5556
public void InterlockedBoolean_ImplicitFromBool_ReturnsExpected(bool value)
5657
{
5758
// Arrange
58-
var tboolValue = ToTBool(value);
59+
var expected = ToTBool(value);
5960

6061
// Act
6162
InterlockedBoolean actual = value;
6263

6364
// Assert
64-
actual._value.Should().Be(tboolValue);
65+
actual.ValueForTests.Should().Be(expected);
6566
}
6667

6768
[Theory]
@@ -73,12 +74,13 @@ public void InterlockedBoolean_Exchange_ReturnsExpected(bool initialState, bool
7374
{
7475
// Arrange
7576
var sut = new InterlockedBoolean(initialState);
77+
var expected = initialState;
7678

7779
// Act
7880
var result = sut.Exchange(newValue);
7981

8082
// Assert
81-
result.Should().Be(initialState);
83+
result.Should().Be(expected);
8284
}
8385

8486
[Theory]
@@ -91,13 +93,13 @@ public void InterlockedBoolean_Exchange_SetsExpectedNewState(bool initialState,
9193
// Arrange
9294
var sut = new InterlockedBoolean(initialState);
9395

94-
var tboolNewValue = ToTBool(newValue);
96+
var expected = ToTBool(newValue);
9597

9698
// Act
9799
var result = sut.Exchange(newValue);
98100

99101
// Assert
100-
sut._value.Should().Be(tboolNewValue);
102+
sut.ValueForTests.Should().Be(expected);
101103
}
102104

103105
[Theory]
@@ -113,12 +115,13 @@ public void InterlockedBoolean_CompareExchange_ReturnsExpected(bool initialState
113115
{
114116
// Arrange
115117
var sut = new InterlockedBoolean(initialState);
118+
var expected = initialState;
116119

117120
// Act
118121
var result = sut.CompareExchange(newValue, comparand);
119122

120123
// Assert
121-
result.Should().Be(initialState);
124+
result.Should().Be(expected);
122125
}
123126

124127
[Theory]
@@ -135,7 +138,7 @@ public void InterlockedBoolean_CompareExchange_SetsExpectedNewState(bool initial
135138
// Arrange
136139
var sut = new InterlockedBoolean(initialState);
137140

138-
var tboolExpected = ToTBool(
141+
var expected = ToTBool(
139142
initialState == comparand
140143
? newValue
141144
: initialState);
@@ -144,6 +147,6 @@ public void InterlockedBoolean_CompareExchange_SetsExpectedNewState(bool initial
144147
sut.CompareExchange(newValue, comparand);
145148

146149
// Assert
147-
sut._value.Should().Be(tboolExpected);
150+
sut.ValueForTests.Should().Be(expected);
148151
}
149152
}

0 commit comments

Comments
 (0)