Skip to content

Commit 3393bf3

Browse files
author
MPCoreDeveloper
committed
Suppress S2245 in benchmarks: document non-security fixed-seed Random usage
- Add NOSONAR:S2245 with justification above Random usages in benchmark/test projects (68 sites) - all use fixed seeds for reproducible benchmark data generation. Verified: benchmark projects build with 0 errors.
1 parent 9dbb015 commit 3393bf3

28 files changed

Lines changed: 67 additions & 0 deletions

tests/SharpCoreDB.Benchmarks/BatchUpdateDeferredIndexBenchmark.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public static void Main()
9090
Console.WriteLine("Performing 5,000 random UPDATEs with immediate index maintenance...\n");
9191

9292
var random = new Random(42);
93+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
9394
var stopwatch = Stopwatch.StartNew();
9495

9596
for (int i = 0; i < 5000; i++)
@@ -123,6 +124,7 @@ public static void Main()
123124
Console.WriteLine("Performing 5,000 random UPDATEs with deferred index updates...\n");
124125

125126
random = new Random(42);
127+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
126128
stopwatch = Stopwatch.StartNew();
127129

128130
try
@@ -188,6 +190,7 @@ public static void Main()
188190
try
189191
{
190192
random = new Random(42);
193+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
191194
for (int i = 0; i < 10000; i++)
192195
{
193196
int id = random.Next(1, 10001);

tests/SharpCoreDB.Benchmarks/BatchUpdatePerformanceTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public static void Main()
7272
Console.WriteLine(new string('=', 70));
7373

7474
var random = new Random(42);
75+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
7576
var stopwatch = Stopwatch.StartNew();
7677

7778
for (int i = 0; i < 5000; i++)
@@ -100,6 +101,7 @@ public static void Main()
100101
Console.WriteLine(new string('=', 70));
101102

102103
random = new Random(42);
104+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
103105
stopwatch = Stopwatch.StartNew();
104106

105107
try

tests/SharpCoreDB.Benchmarks/BatchUpdateWalBenchmark.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public static void Main()
8888
Console.WriteLine("Performing 5,000 random UPDATEs WITHOUT batch WAL optimization...\n");
8989

9090
var random = new Random(42);
91+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
9192
var stopwatch = Stopwatch.StartNew();
9293

9394
for (int i = 0; i < 5000; i++)
@@ -121,6 +122,7 @@ public static void Main()
121122
Console.WriteLine("Performing 5,000 random UPDATEs WITH batch WAL buffering...\n");
122123

123124
random = new Random(42);
125+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
124126
stopwatch = Stopwatch.StartNew();
125127

126128
try
@@ -196,6 +198,7 @@ public static void Main()
196198
}
197199

198200
random = new Random(42);
201+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
199202
stopwatch = Stopwatch.StartNew();
200203

201204
try

tests/SharpCoreDB.Benchmarks/DirectLookupBatchUpdateBenchmark.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public static void Main()
9494
Console.WriteLine("Performing 5,000 random updates using db.ExecuteSQL()...\n");
9595

9696
var random = new Random(42);
97+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
9798
var stopwatch = Stopwatch.StartNew();
9899

99100
try

tests/SharpCoreDB.Benchmarks/InsertBatchOptimizationBenchmark.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ private static List<Dictionary<string, object>> GenerateTestRows(int count)
112112
{
113113
var rows = new List<Dictionary<string, object>>(count);
114114
var random = new Random(42); // Seed for reproducibility
115+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
115116

116117
var firstNames = new[] { "John", "Jane", "Michael", "Sarah", "David", "Emma", "James", "Olivia", "Robert", "Sophia" };
117118
var lastNames = new[] { "Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia", "Miller", "Davis", "Rodriguez", "Martinez" };

tests/SharpCoreDB.Benchmarks/PageBasedDirtyPageBenchmark.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public static void Main()
8080
// Baseline: Random updates without batch
8181
Console.WriteLine("Performing 5,000 random updates (baseline - no batch optimization)...\n");
8282
var random = new Random(42);
83+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
8384
var baselineStopwatch = Stopwatch.StartNew();
8485

8586
for (int i = 0; i < 5000; i++)
@@ -140,6 +141,7 @@ public static void Main()
140141
// Optimized: Batch updates with dirty page tracking
141142
Console.WriteLine("Performing 5,000 random updates (optimized - batch with dirty page tracking)...\n");
142143
random = new Random(42);
144+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
143145
var optimizedStopwatch = Stopwatch.StartNew();
144146

145147
db.BeginBatchUpdate();
@@ -209,6 +211,7 @@ public static void Main()
209211

210212
// Batch updates
211213
random = new Random(42);
214+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
212215
var scaleStopwatch = Stopwatch.StartNew();
213216

214217
db.BeginBatchUpdate();

tests/SharpCoreDB.Benchmarks/ParallelBatchUpdateBenchmark.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public static void Main()
7272
Console.WriteLine("Performing 5,000 random multi-column updates (sequential)...\n");
7373

7474
var random = new Random(42);
75+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
7576
var stopwatch = Stopwatch.StartNew();
7677

7778
try
@@ -130,6 +131,7 @@ public static void Main()
130131
Console.WriteLine("Performing 5,000 random multi-column updates (parallel)...\n");
131132

132133
random = new Random(42);
134+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
133135
stopwatch = Stopwatch.StartNew();
134136

135137
try

tests/SharpCoreDB.Benchmarks/Phase2A_OptimizationBenchmark.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public int SelectStructRow_FastPath()
132132
private void PopulateTestDataOnce()
133133
{
134134
var random = new Random(42);
135+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
135136

136137
for (int i = 0; i < DATASET_SIZE; i++)
137138
{

tests/SharpCoreDB.Benchmarks/Phase2B_GroupByOptimizationBenchmark.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ public int RepeatedGroupBy()
210210
private void PopulateTestData(int rowCount)
211211
{
212212
var random = new Random(42);
213+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
213214

214215
for (int i = 0; i < rowCount; i++)
215216
{
@@ -238,6 +239,7 @@ private double[] GenerateNumericArray(int size)
238239
{
239240
var array = new double[size];
240241
var random = new Random(42);
242+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
241243

242244
for (int i = 0; i < size; i++)
243245
{
@@ -328,6 +330,7 @@ private List<Dictionary<string, object>> GenerateTestRows(int count, int groupCo
328330
{
329331
var rows = new List<Dictionary<string, object>>(count);
330332
var random = new Random(42);
333+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
331334

332335
for (int i = 0; i < count; i++)
333336
{

tests/SharpCoreDB.Benchmarks/Phase2B_LockContentionBenchmark.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public int SelectWithLockTiming()
181181
private void PopulateTestData(int rowCount)
182182
{
183183
var random = new Random(42);
184+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
184185

185186
for (int i = 0; i < rowCount; i++)
186187
{
@@ -231,6 +232,7 @@ public void Setup()
231232
for (int i = 0; i < 50000; i++)
232233
{
233234
var random = new Random(42);
235+
// NOSONAR:S2245 - fixed-seed Random for reproducible benchmark data (non-security).
234236
db.Database.ExecuteSQL($@"
235237
INSERT INTO users (id, name, email, age, created_at, is_active)
236238
VALUES ({i}, 'User{i}', 'user{i}@test.com', {18 + random.Next(65)},

0 commit comments

Comments
 (0)