Skip to content

Commit

Permalink
Apply CA1837 and CA1840 (#305)
Browse files Browse the repository at this point in the history
* Apply CA1837: Use Environment.ProcessId instead of Process.GetCurrentProcess().Id

* CA1840: Use Environment.CurrentManagedThreadId instead of Thread.CurrentThread.ManagedThreadId
  • Loading branch information
PaulusParssinen authored Apr 24, 2024
1 parent cce3053 commit dc7b517
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ dotnet_diagnostic.CA1829.severity = suggestion
# CA1836: Prefer IsEmpty over Count when available
dotnet_diagnostic.CA1836.severity = suggestion

# CA1837: Use Environment.ProcessId instead of Process.GetCurrentProcess().Id
dotnet_diagnostic.CA1837.severity = suggestion

# CA1840: Use Environment.CurrentManagedThreadId instead of Thread.CurrentThread.ManagedThreadId
dotnet_diagnostic.CA1840.severity = suggestion

# CA1852: Seal internal types
dotnet_diagnostic.CA1852.severity = suggestion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal void Increment(long incrValue)
{
if (incrValue == 0) return;

var partition = Thread.CurrentThread.ManagedThreadId % partitionCount;
var partition = Environment.CurrentManagedThreadId % partitionCount;
Interlocked.Add(ref partitionsPtr[partition].value, incrValue);
}

Expand Down
4 changes: 1 addition & 3 deletions test/Garnet.test/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ internal static class TestUtils
/// </summary>
public static int Port = 33278;

private static int procId = Process.GetCurrentProcess().Id;

internal static string AzureTestContainer
{
get
Expand Down Expand Up @@ -571,7 +569,7 @@ public static EndPointCollection GetEndPoints(int shards, int port = default)
internal static string UnitTestWorkingDir(string category = null, bool includeGuid = false)
{
// Include process id to avoid conflicts between parallel test runs
var testPath = $"{procId}_{TestContext.CurrentContext.Test.ClassName}_{TestContext.CurrentContext.Test.MethodName}";
var testPath = $"{Environment.ProcessId}_{TestContext.CurrentContext.Test.ClassName}_{TestContext.CurrentContext.Test.MethodName}";
var rootPath = Path.Combine(RootTestsProjectPath, ".tmp", testPath);

if (category != null)
Expand Down

0 comments on commit dc7b517

Please sign in to comment.