@@ -14,8 +14,10 @@ import (
1414 "strings"
1515 "sync"
1616 "testing"
17+ "testing/synctest"
1718 "time"
1819
20+ "github.com/cockroachdb/crlib/testutils/leaktest"
1921 "github.com/cockroachdb/datadriven"
2022 "github.com/cockroachdb/pebble/internal/testutils"
2123 "github.com/cockroachdb/pebble/vfs"
@@ -572,41 +574,45 @@ func recvWithDeadline(t *testing.T, td *datadriven.TestData, waitStr string, ch
572574}
573575
574576func TestFailoverManager_Quiesce (t * testing.T ) {
575- seed := time .Now ().UnixNano ()
576- memFS := vfs .NewMem ()
577- require .NoError (t , memFS .MkdirAll ("primary" , os .ModePerm ))
578- require .NoError (t , memFS .MkdirAll ("secondary" , os .ModePerm ))
579- fs := errorfs .Wrap (memFS , errorfs .RandomLatency (
580- errorfs .Randomly (0.50 , seed ), 10 * time .Millisecond , seed , 0 /* no limit */ ))
581-
582- var m failoverManager
583- require .NoError (t , m .init (Options {
584- Primary : Dir {FS : fs , Dirname : "primary" },
585- Secondary : Dir {FS : fs , Dirname : "secondary" },
586- MaxNumRecyclableLogs : 2 ,
587- PreallocateSize : func () int { return 4 },
588- FailoverOptions : FailoverOptions {
589- PrimaryDirProbeInterval : 250 * time .Microsecond ,
590- HealthyProbeLatencyThreshold : time .Millisecond ,
591- HealthyInterval : 3 * time .Millisecond ,
592- UnhealthySamplingInterval : 250 * time .Microsecond ,
593- UnhealthyOperationLatencyThreshold : func () (time.Duration , bool ) { return time .Millisecond , true },
594- },
595- FailoverWriteAndSyncLatency : prometheus .NewHistogram (prometheus.HistogramOpts {}),
596- WriteWALSyncOffsets : func () bool { return false },
597- }, nil /* initial logs */ ))
598- for i := 0 ; i < 3 ; i ++ {
599- w , err := m .Create (NumWAL (i ), i )
600- require .NoError (t , err )
601- _ , err = w .WriteRecord ([]byte ("hello world" ), SyncOptions {}, nil )
602- require .NoError (t , err )
603- _ , err = w .Close ()
604- require .NoError (t , err )
605- }
606- require .NoError (t , m .Close ())
577+ synctest .Test (t , func (t * testing.T ) {
578+ seed := time .Now ().UnixNano ()
579+ memFS := vfs .NewMem ()
580+ require .NoError (t , memFS .MkdirAll ("primary" , os .ModePerm ))
581+ require .NoError (t , memFS .MkdirAll ("secondary" , os .ModePerm ))
582+ fs := errorfs .Wrap (memFS , errorfs .RandomLatency (
583+ errorfs .Randomly (0.50 , seed ), 10 * time .Millisecond , seed , 0 /* no limit */ ))
584+
585+ var m failoverManager
586+ require .NoError (t , m .init (Options {
587+ Primary : Dir {FS : fs , Dirname : "primary" },
588+ Secondary : Dir {FS : fs , Dirname : "secondary" },
589+ MaxNumRecyclableLogs : 2 ,
590+ PreallocateSize : func () int { return 4 },
591+ FailoverOptions : FailoverOptions {
592+ PrimaryDirProbeInterval : 250 * time .Microsecond ,
593+ HealthyProbeLatencyThreshold : time .Millisecond ,
594+ HealthyInterval : 3 * time .Millisecond ,
595+ UnhealthySamplingInterval : 250 * time .Microsecond ,
596+ UnhealthyOperationLatencyThreshold : func () (time.Duration , bool ) { return time .Millisecond , true },
597+ },
598+ FailoverWriteAndSyncLatency : prometheus .NewHistogram (prometheus.HistogramOpts {}),
599+ WriteWALSyncOffsets : func () bool { return false },
600+ }, nil /* initial logs */ ))
601+ for i := range 3 {
602+ w , err := m .Create (NumWAL (i ), i )
603+ require .NoError (t , err )
604+ _ , err = w .WriteRecord ([]byte ("hello world" ), SyncOptions {}, nil )
605+ require .NoError (t , err )
606+ _ , err = w .Close ()
607+ require .NoError (t , err )
608+ }
609+ require .NoError (t , m .Close ())
610+ })
607611}
608612
609613func TestFailoverManager_SecondaryIsWritable (t * testing.T ) {
614+ defer leaktest .AfterTest (t )()
615+
610616 var m failoverManager
611617 require .EqualError (t , m .init (Options {
612618 Primary : Dir {FS : vfs .NewMem (), Dirname : "primary" },
@@ -627,6 +633,8 @@ func TestFailoverManager_SecondaryIsWritable(t *testing.T) {
627633// that all the files that are created by the manager are eventually returned by
628634// FailoverManager.Obsolete for deletion.
629635func TestFailoverManager_AllFilesDeletable (t * testing.T ) {
636+ defer leaktest .AfterTest (t )()
637+
630638 seed := time .Now ().UnixNano ()
631639 memFS := vfs .NewMem ()
632640 require .NoError (t , memFS .MkdirAll ("primary" , os .ModePerm ))
@@ -638,6 +646,7 @@ func TestFailoverManager_AllFilesDeletable(t *testing.T) {
638646 errorfs .Randomly (0.50 , latencySeed ), 10 * time .Millisecond , latencySeed , 0 /* no limit */ ))
639647
640648 var m failoverManager
649+ defer func () { require .NoError (t , m .Close ()) }()
641650 require .NoError (t , m .init (Options {
642651 Primary : Dir {FS : fs , Dirname : "primary" },
643652 Secondary : Dir {FS : fs , Dirname : "secondary" },
0 commit comments