@@ -290,6 +290,9 @@ type kvnemesisTestCfg struct {
290
290
// transactions, this will apply to all transactions.
291
291
bufferedWriteProb float64 // [0,1)
292
292
293
+ // If enabled, set the user priority of transactions to a random value.
294
+ randomUserPriority bool
295
+
293
296
// If enabled, track Raft proposals and command application, and assert
294
297
// invariants (in particular that we don't double-apply a request or
295
298
// proposal).
@@ -310,34 +313,37 @@ type kvnemesisTestCfg struct {
310
313
testGeneratorConfig func (* GeneratorConfig )
311
314
}
312
315
313
- func TestKVNemesisSingleNode (t * testing.T ) {
314
- defer leaktest .AfterTest (t )()
315
- defer log .Scope (t ).Close (t )
316
-
317
- testKVNemesisImpl (t , kvnemesisTestCfg {
318
- numNodes : 1 ,
316
+ func defaultTestConfiguration (numNodes int ) kvnemesisTestCfg {
317
+ return kvnemesisTestCfg {
318
+ numNodes : numNodes ,
319
319
numSteps : defaultNumSteps ,
320
320
concurrency : 5 ,
321
321
seedOverride : 0 ,
322
322
invalidLeaseAppliedIndexProb : 0.2 ,
323
323
injectReproposalErrorProb : 0.2 ,
324
324
assertRaftApply : true ,
325
- })
325
+ randomUserPriority : true ,
326
+ }
327
+ }
328
+
329
+ func TestKVNemesisSingleNode (t * testing.T ) {
330
+ defer leaktest .AfterTest (t )()
331
+ defer log .Scope (t ).Close (t )
332
+ cfg := defaultTestConfiguration (1 )
333
+ cfg .seedOverride = 0
334
+ testKVNemesisImpl (t , cfg )
326
335
}
327
336
328
337
func TestKVNemesisSingleNode_ReproposalChaos (t * testing.T ) {
329
338
defer leaktest .AfterTest (t )()
330
339
defer log .Scope (t ).Close (t )
331
340
332
- testKVNemesisImpl (t , kvnemesisTestCfg {
333
- numNodes : 1 ,
334
- numSteps : defaultNumSteps ,
335
- concurrency : 5 ,
336
- seedOverride : 0 ,
337
- invalidLeaseAppliedIndexProb : 0.9 ,
338
- injectReproposalErrorProb : 0.5 ,
339
- assertRaftApply : true ,
340
- })
341
+ cfg := defaultTestConfiguration (1 )
342
+ cfg .seedOverride = 0
343
+ cfg .invalidLeaseAppliedIndexProb = 0.9
344
+ cfg .injectReproposalErrorProb = 0.5
345
+
346
+ testKVNemesisImpl (t , cfg )
341
347
}
342
348
343
349
// TestKVNemesisMultiNode_BufferedWritesNoLockDurabilityUpgrades runs KVNemesis
@@ -346,21 +352,15 @@ func TestKVNemesisSingleNode_ReproposalChaos(t *testing.T) {
346
352
func TestKVNemesisMultiNode_BufferedWritesNoLockDurabilityUpgrades (t * testing.T ) {
347
353
defer leaktest .AfterTest (t )()
348
354
defer log .Scope (t ).Close (t )
349
-
350
- testKVNemesisImpl (t , kvnemesisTestCfg {
351
- numNodes : 3 ,
352
- numSteps : defaultNumSteps ,
353
- concurrency : 5 ,
354
- seedOverride : 0 ,
355
- invalidLeaseAppliedIndexProb : 0.2 ,
356
- injectReproposalErrorProb : 0.2 ,
357
- assertRaftApply : true ,
358
- bufferedWriteProb : 0.70 ,
359
- testSettings : func (ctx context.Context , st * cluster.Settings ) {
360
- concurrency .UnreplicatedLockReliabilityLeaseTransfer .Override (ctx , & st .SV , false )
361
- concurrency .UnreplicatedLockReliabilityMerge .Override (ctx , & st .SV , false )
362
- kvcoord .BufferedWritesEnabled .Override (ctx , & st .SV , true )
363
- }})
355
+ cfg := defaultTestConfiguration (3 )
356
+ cfg .seedOverride = 0
357
+ cfg .bufferedWriteProb = 0.7
358
+ cfg .testSettings = func (ctx context.Context , st * cluster.Settings ) {
359
+ concurrency .UnreplicatedLockReliabilityLeaseTransfer .Override (ctx , & st .SV , false )
360
+ concurrency .UnreplicatedLockReliabilityMerge .Override (ctx , & st .SV , false )
361
+ kvcoord .BufferedWritesEnabled .Override (ctx , & st .SV , true )
362
+ }
363
+ testKVNemesisImpl (t , cfg )
364
364
}
365
365
366
366
// TestKVNemesisMultiNode_BufferedWritesLockDurabilityUpgrades tests buffered
@@ -369,22 +369,17 @@ func TestKVNemesisMultiNode_BufferedWritesLockDurabilityUpgrades(t *testing.T) {
369
369
defer leaktest .AfterTest (t )()
370
370
defer log .Scope (t ).Close (t )
371
371
372
- testKVNemesisImpl (t , kvnemesisTestCfg {
373
- numNodes : 3 ,
374
- numSteps : defaultNumSteps ,
375
- concurrency : 5 ,
376
- seedOverride : 0 ,
377
- invalidLeaseAppliedIndexProb : 0.2 ,
378
- injectReproposalErrorProb : 0.2 ,
379
- assertRaftApply : true ,
380
- bufferedWriteProb : 0.70 ,
381
- testSettings : func (ctx context.Context , st * cluster.Settings ) {
382
- kvcoord .BufferedWritesEnabled .Override (ctx , & st .SV , true )
383
- concurrency .UnreplicatedLockReliabilityLeaseTransfer .Override (ctx , & st .SV , true )
384
- concurrency .UnreplicatedLockReliabilityMerge .Override (ctx , & st .SV , true )
385
- concurrency .UnreplicatedLockReliabilitySplit .Override (ctx , & st .SV , true )
386
- },
387
- })
372
+ cfg := defaultTestConfiguration (3 )
373
+ cfg .seedOverride = 0
374
+ cfg .bufferedWriteProb = 0.7
375
+ cfg .testSettings = func (ctx context.Context , st * cluster.Settings ) {
376
+ kvcoord .BufferedWritesEnabled .Override (ctx , & st .SV , true )
377
+ concurrency .UnreplicatedLockReliabilityLeaseTransfer .Override (ctx , & st .SV , true )
378
+ concurrency .UnreplicatedLockReliabilityMerge .Override (ctx , & st .SV , true )
379
+ concurrency .UnreplicatedLockReliabilitySplit .Override (ctx , & st .SV , true )
380
+ }
381
+
382
+ testKVNemesisImpl (t , cfg )
388
383
}
389
384
390
385
// TestKVNemesisMultiNode_BufferedWritesNoPipelining turns on buffered
@@ -393,38 +388,36 @@ func TestKVNemesisMultiNode_BufferedWritesNoPipelining(t *testing.T) {
393
388
defer leaktest .AfterTest (t )()
394
389
defer log .Scope (t ).Close (t )
395
390
396
- testKVNemesisImpl (t , kvnemesisTestCfg {
397
- numNodes : 3 ,
398
- numSteps : defaultNumSteps ,
399
- concurrency : 5 ,
400
- seedOverride : 0 ,
401
- invalidLeaseAppliedIndexProb : 0.2 ,
402
- injectReproposalErrorProb : 0.2 ,
403
- assertRaftApply : true ,
404
- bufferedWriteProb : 0.70 ,
405
- testSettings : func (ctx context.Context , st * cluster.Settings ) {
406
- kvcoord .BufferedWritesEnabled .Override (ctx , & st .SV , true )
407
- kvcoord .PipelinedWritesEnabled .Override (ctx , & st .SV , false )
408
- concurrency .UnreplicatedLockReliabilityLeaseTransfer .Override (ctx , & st .SV , true )
409
- concurrency .UnreplicatedLockReliabilityMerge .Override (ctx , & st .SV , true )
410
- concurrency .UnreplicatedLockReliabilitySplit .Override (ctx , & st .SV , true )
411
- },
412
- })
391
+ cfg := defaultTestConfiguration (3 )
392
+ cfg .seedOverride = 0
393
+ cfg .bufferedWriteProb = 0.7
394
+ cfg .testSettings = func (ctx context.Context , st * cluster.Settings ) {
395
+ kvcoord .BufferedWritesEnabled .Override (ctx , & st .SV , true )
396
+ kvcoord .PipelinedWritesEnabled .Override (ctx , & st .SV , false )
397
+ concurrency .UnreplicatedLockReliabilityLeaseTransfer .Override (ctx , & st .SV , true )
398
+ concurrency .UnreplicatedLockReliabilityMerge .Override (ctx , & st .SV , true )
399
+ concurrency .UnreplicatedLockReliabilitySplit .Override (ctx , & st .SV , true )
400
+ }
401
+ testKVNemesisImpl (t , cfg )
413
402
}
414
403
415
404
func TestKVNemesisMultiNode (t * testing.T ) {
416
405
defer leaktest .AfterTest (t )()
417
406
defer log .Scope (t ).Close (t )
407
+ cfg := defaultTestConfiguration (4 )
408
+ cfg .seedOverride = 0
409
+ testKVNemesisImpl (t , cfg )
410
+ }
418
411
419
- testKVNemesisImpl ( t , kvnemesisTestCfg {
420
- numNodes : 4 ,
421
- numSteps : defaultNumSteps ,
422
- concurrency : 5 ,
423
- seedOverride : 0 ,
424
- invalidLeaseAppliedIndexProb : 0.2 ,
425
- injectReproposalErrorProb : 0.2 ,
426
- assertRaftApply : true ,
427
- } )
412
+ func TestKVNemesisMultiNode_LeaderLeases ( t * testing. T ) {
413
+ defer leaktest . AfterTest ( t )()
414
+ defer log . Scope ( t ). Close ( t )
415
+
416
+ cfg := defaultTestConfiguration ( 4 )
417
+ cfg . seedOverride = 0
418
+ cfg . leaseTypeOverride = roachpb . LeaseLeader
419
+
420
+ testKVNemesisImpl ( t , cfg )
428
421
}
429
422
430
423
// FuzzKVNemesisSingleNode is an attempt ot make it possible to run KVNemesis
@@ -434,56 +427,27 @@ func FuzzKVNemesisSingleNode(f *testing.F) {
434
427
defer leaktest .AfterTest (f )()
435
428
defer log .Scope (f ).Close (f )
436
429
437
- const (
438
- // Set to > 0 to pre-generate corpus data.
439
- corpusSize = 0
440
- // I've set these to low values for now to at least get things running
441
- // reliably. With all default settings the test runner fails without
442
- // printing any useful info. I _think_ it might be the result of a
443
- // hard-coded 10s timeout in the go-fuzz test worker.
444
- numStep = 10
445
- concurrency = 1
446
- )
430
+ // Set to > 0 to pre-generate corpus data.
431
+ const corpusSize = 0
432
+
433
+ cfg := defaultTestConfiguration (1 )
434
+ // I've set these to low values for now to at least get things running
435
+ // reliably. With all default settings the test runner fails without
436
+ // printing any useful info. I _think_ it might be the result of a
437
+ // hard-coded 10s timeout in the go-fuzz test worker.
438
+ cfg .numSteps = 10
439
+ cfg .concurrency = 1
440
+
447
441
for range corpusSize {
448
442
rndSource := randutil .NewRecordingRandSource (rand .NewSource (randutil .NewPseudoSeed ()).(rand.Source64 ))
449
- testKVNemesisImpl (f , kvnemesisTestCfg {
450
- numNodes : 1 ,
451
- numSteps : numStep ,
452
- concurrency : concurrency ,
453
- randSource : rndSource ,
454
- invalidLeaseAppliedIndexProb : 0.2 ,
455
- injectReproposalErrorProb : 0.2 ,
456
- assertRaftApply : true ,
457
- })
443
+ cfg .randSource = rndSource
444
+ testKVNemesisImpl (f , cfg )
458
445
f .Add (rndSource .Output ())
459
446
}
460
447
461
448
f .Fuzz (func (t * testing.T , data []byte ) {
462
- testKVNemesisImpl (t , kvnemesisTestCfg {
463
- numNodes : 1 ,
464
- numSteps : numStep ,
465
- concurrency : concurrency ,
466
- randSource : randutil .NewFuzzRandSource (t , data ),
467
- invalidLeaseAppliedIndexProb : 0.2 ,
468
- injectReproposalErrorProb : 0.2 ,
469
- assertRaftApply : true ,
470
- })
471
- })
472
- }
473
-
474
- func TestKVNemesisMultiNode_LeaderLeases (t * testing.T ) {
475
- defer leaktest .AfterTest (t )()
476
- defer log .Scope (t ).Close (t )
477
-
478
- testKVNemesisImpl (t , kvnemesisTestCfg {
479
- numNodes : 4 ,
480
- numSteps : defaultNumSteps ,
481
- concurrency : 5 ,
482
- seedOverride : 0 ,
483
- invalidLeaseAppliedIndexProb : 0.2 ,
484
- injectReproposalErrorProb : 0.2 ,
485
- assertRaftApply : true ,
486
- leaseTypeOverride : roachpb .LeaseLeader ,
449
+ cfg .randSource = randutil .NewFuzzRandSource (t , data )
450
+ testKVNemesisImpl (t , cfg )
487
451
})
488
452
}
489
453
@@ -519,7 +483,8 @@ func testKVNemesisImpl(t testing.TB, cfg kvnemesisTestCfg) {
519
483
config := NewDefaultConfig ()
520
484
config .NumNodes = cfg .numNodes
521
485
config .NumReplicas = 3
522
- config .BufferedWritesProb = cfg .bufferedWriteProb
486
+ config .TxnConfig .BufferedWritesProb = cfg .bufferedWriteProb
487
+ config .TxnConfig .RandomUserPriority = cfg .randomUserPriority
523
488
524
489
config .SeedForLogging = seed
525
490
config .RandSourceCounterForLogging = countingSource
0 commit comments