Add FileReplica.Sync() unit tests.

This commit is contained in:
Ben Johnson
2021-01-05 15:48:50 -07:00
parent 3075b2e92b
commit b22f3f100d
2 changed files with 101 additions and 0 deletions

View File

@@ -89,6 +89,10 @@ type FileReplica struct {
wg sync.WaitGroup
ctx context.Context
cancel func()
// If true, replica monitors database for changes automatically.
// Set to false if replica is being used synchronously (such as in tests).
MonitorEnabled bool
}
// NewFileReplica returns a new instance of FileReplica.
@@ -98,6 +102,8 @@ func NewFileReplica(db *DB, name, dst string) *FileReplica {
name: name,
dst: dst,
cancel: func() {},
MonitorEnabled: true,
}
}
@@ -406,6 +412,11 @@ func (r *FileReplica) WALs(ctx context.Context) ([]*WALInfo, error) {
// Start starts replication for a given generation.
func (r *FileReplica) Start(ctx context.Context) {
// Ignore if replica is being used sychronously.
if !r.MonitorEnabled {
return
}
// Stop previous replication.
r.Stop()