Skip to content

ConcurrentDictionary in C#: retarget net10.0, NUnit 4.6.1, add the unsized naive example - #2230

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/78691-concurrentdictionary-csharp
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/78691-concurrentdictionary-csharp

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Updates the sample for the ConcurrentDictionary in C# article (collections-csharp/ConcurrentDictionary only).

Changes:

  • Both projects move from net7.0 to net10.0.
  • Test packages, each re-queried on NuGet on 2026-09-23 (newest stable): Microsoft.NET.Test.Sdk 17.3.2 to 18.10.1, NUnit 3.13.3 to 4.6.1, NUnit3TestAdapter 4.2.1 to 6.3.0, NUnit.Analyzers 3.3.0 to 4.15.0, coverlet.collector 3.1.2 to 10.0.1. The batch plan named Microsoft.NET.Test.Sdk 18.10.0; 18.10.1 is current and is what this PR uses.
  • NUnit 4.6.1: Assert.IsTrue, Assert.IsFalse and Assert.Greater compile unchanged from NUnit.Framework on net10.0, so no assertion is rewritten and nothing moves to ClassicAssert.
  • New NaiveExampleUnsized.cs holds the unsized Dictionary example the article opens with. Program.cs runs it first, inside a try/catch that prints the AggregateException. It has no test because the throw depends on thread timing.
  • ContentionExample: the emptyHits local was incremented and never read. It is removed and the empty-state check is called directly, which is the cost the example measures.
  • ContentionExampleIntegrationTest: the wall-clock comparison test is renamed to WhenBothVariantsRun_ThenTheSecondVariantTakesMoreTime_Live so the CI filter FullyQualifiedName!~Live skips it. It still runs locally.
  • ContentionExampleIntegrationTest and MemoryLeakExampleIntegrationTest: the sut field was created twice, once by its initialiser and again in [SetUp]. The initialiser is dropped.
  • Program.cs prints one line before ContentionExample and one before MemoryLeakExample so the program does not look stuck.

Verified locally on SDK 10.0.302, runtime 10.0.10: dotnet build -c Release with 0 warnings and 0 errors; dotnet test with 10 of 10 passing, and 9 of 9 with the CI filter; dotnet list package --vulnerable --include-transitive reports nothing.

…sized naive example

- Both projects net7.0 to net10.0.
- Microsoft.NET.Test.Sdk 18.10.1, NUnit 4.6.1, NUnit3TestAdapter 6.3.0,
  NUnit.Analyzers 4.15.0, coverlet.collector 10.0.1. The classic asserts
  compile unchanged on NUnit 4.6.1, so no test assertion is rewritten.
- Add NaiveExampleUnsized, the unsized Dictionary the article opens with,
  and run it from Program.cs inside a try/catch that prints the exception.
  No test for it: the throw is probabilistic.
- ContentionExample: remove the unused emptyHits local and call the
  empty-state check directly.
- Rename the wall-clock comparison test to end in _Live so CI skips it.
- Drop the duplicate sut field initialisers that [SetUp] already assigns.
- Program.cs names the two slower examples before running them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant