@@ -371,8 +371,9 @@ func randomAction() action {
371
371
372
372
func trackerWorker (i int , stop <- chan struct {}) {
373
373
log := newDebugLogger (900 + i )
374
- txn := fuzzDB .ReadTxn ()
375
- iter , err := tableFuzz1 .Changes (txn )
374
+ wtxn := fuzzDB .WriteTxn (tableFuzz1 )
375
+ iter , err := tableFuzz1 .Changes (wtxn )
376
+ wtxn .Commit ()
376
377
if err != nil {
377
378
panic (err )
378
379
}
@@ -381,6 +382,7 @@ func trackerWorker(i int, stop <-chan struct{}) {
381
382
// Keep track of what state the changes lead us to in order to validate it.
382
383
state := map [uint64 ]* statedb.Change [fuzzObj ]{}
383
384
385
+ var txn statedb.ReadTxn
384
386
var prevRev statedb.Revision
385
387
for {
386
388
for change , rev , ok := iter .Next (); ok ; change , rev , ok = iter .Next () {
@@ -406,31 +408,34 @@ func trackerWorker(i int, stop <-chan struct{}) {
406
408
state [change .Object .id ] = & change
407
409
}
408
410
}
409
- // Validate that the observed changes match with the database state at this
410
- // snapshot.
411
- state2 := maps .Clone (state )
412
- iterAll , _ := tableFuzz1 .All (txn )
413
- for obj , rev , ok := iterAll .Next (); ok ; obj , rev , ok = iterAll .Next () {
414
- change , found := state [obj .id ]
415
- if ! found {
416
- panic (fmt .Sprintf ("trackerWorker: object %d not found from state" , obj .id ))
417
- }
418
411
419
- if change .Revision != rev {
420
- panic (fmt .Sprintf ("trackerWorker: last observed revision %d does not match real revision %d" , change .Revision , rev ))
421
- }
412
+ if txn != nil {
413
+ // Validate that the observed changes match with the database state at this
414
+ // snapshot.
415
+ state2 := maps .Clone (state )
416
+ iterAll , _ := tableFuzz1 .All (txn )
417
+ for obj , rev , ok := iterAll .Next (); ok ; obj , rev , ok = iterAll .Next () {
418
+ change , found := state [obj .id ]
419
+ if ! found {
420
+ panic (fmt .Sprintf ("trackerWorker: object %d not found from state" , obj .id ))
421
+ }
422
+
423
+ if change .Revision != rev {
424
+ panic (fmt .Sprintf ("trackerWorker: last observed revision %d does not match real revision %d" , change .Revision , rev ))
425
+ }
422
426
423
- if change .Object .value != obj .value {
424
- panic (fmt .Sprintf ("trackerWorker: observed value %d does not match real value %d" , change .Object .value , obj .value ))
427
+ if change .Object .value != obj .value {
428
+ panic (fmt .Sprintf ("trackerWorker: observed value %d does not match real value %d" , change .Object .value , obj .value ))
429
+ }
430
+ delete (state2 , obj .id )
425
431
}
426
- delete (state2 , obj .id )
427
- }
428
432
429
- if len (state ) != tableFuzz1 .NumObjects (txn ) {
430
- for id := range state2 {
431
- fmt .Printf ("%d should not exist\n " , id )
433
+ if len (state ) != tableFuzz1 .NumObjects (txn ) {
434
+ for id := range state2 {
435
+ fmt .Printf ("%d should not exist\n " , id )
436
+ }
437
+ panic (fmt .Sprintf ("trackerWorker: state size mismatch: %d vs %d" , len (state ), tableFuzz1 .NumObjects (txn )))
432
438
}
433
- panic (fmt .Sprintf ("trackerWorker: state size mismatch: %d vs %d" , len (state ), tableFuzz1 .NumObjects (txn )))
434
439
}
435
440
436
441
txn = fuzzDB .ReadTxn ()
@@ -524,7 +529,7 @@ func TestDB_Fuzz(t *testing.T) {
524
529
}()
525
530
// Delay a bit to start the trackers at different points in time
526
531
// so they will observe a different starting state.
527
- time .Sleep (100 * time .Millisecond )
532
+ time .Sleep (500 * time .Millisecond )
528
533
}
529
534
530
535
// Wait until the mutation workers stop and then stop
0 commit comments