lib/model: Merge add and start folder funcs and related refactor (#6594)
This commit is contained in:
@@ -19,8 +19,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/db"
|
||||
"github.com/syncthing/syncthing/lib/db/backend"
|
||||
"github.com/syncthing/syncthing/lib/events"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/ignore"
|
||||
@@ -90,37 +88,20 @@ func createFile(t *testing.T, name string, fs fs.Filesystem) protocol.FileInfo {
|
||||
return file
|
||||
}
|
||||
|
||||
// Sets up a folder and model, but makes sure the services aren't actually running.
|
||||
func setupSendReceiveFolder(files ...protocol.FileInfo) (*model, *sendReceiveFolder) {
|
||||
w := createTmpWrapper(defaultCfg)
|
||||
model := newModel(w, myID, "syncthing", "dev", db.NewLowlevel(backend.OpenMemory()), nil)
|
||||
fcfg := testFolderConfigTmp()
|
||||
model.addFolder(fcfg)
|
||||
|
||||
f := &sendReceiveFolder{
|
||||
folder: folder{
|
||||
stateTracker: newStateTracker("default", model.evLogger),
|
||||
model: model,
|
||||
fset: model.folderFiles[fcfg.ID],
|
||||
initialScanFinished: make(chan struct{}),
|
||||
ctx: context.TODO(),
|
||||
FolderConfiguration: fcfg,
|
||||
},
|
||||
|
||||
queue: newJobQueue(),
|
||||
writeLimiter: newByteSemaphore(2),
|
||||
pullErrors: make(map[string]string),
|
||||
pullErrorsMut: sync.NewMutex(),
|
||||
}
|
||||
f.fs = fs.NewMtimeFS(f.Filesystem(), db.NewNamespacedKV(model.db, "mtime"))
|
||||
w, fcfg := tmpDefaultWrapper()
|
||||
model := setupModel(w)
|
||||
model.Supervisor.Stop()
|
||||
f := model.folderRunners[fcfg.ID].(*sendReceiveFolder)
|
||||
f.pullErrors = make(map[string]string)
|
||||
f.ctx = context.Background()
|
||||
|
||||
// Update index
|
||||
if files != nil {
|
||||
f.updateLocalsFromScanning(files)
|
||||
}
|
||||
|
||||
// Folders are never actually started, so no initial scan will be done
|
||||
close(f.initialScanFinished)
|
||||
|
||||
return model, f
|
||||
}
|
||||
|
||||
@@ -392,7 +373,7 @@ func TestWeakHash(t *testing.T) {
|
||||
case pull := <-pullChan:
|
||||
pulls = append(pulls, pull)
|
||||
case <-timeout:
|
||||
t.Errorf("timed out, got %d pulls expected %d", len(pulls), expectPulls)
|
||||
t.Fatalf("timed out, got %d pulls expected %d", len(pulls), expectPulls)
|
||||
}
|
||||
}
|
||||
finish := <-finisherChan
|
||||
@@ -420,7 +401,7 @@ func TestWeakHash(t *testing.T) {
|
||||
case pull := <-pullChan:
|
||||
pulls = append(pulls, pull)
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Errorf("timed out, got %d pulls expected %d", len(pulls), expectPulls)
|
||||
t.Fatalf("timed out, got %d pulls expected %d", len(pulls), expectPulls)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +470,7 @@ func TestDeregisterOnFailInCopy(t *testing.T) {
|
||||
}
|
||||
|
||||
pullChan := make(chan pullBlockState)
|
||||
finisherBufferChan := make(chan *sharedPullerState)
|
||||
finisherBufferChan := make(chan *sharedPullerState, 1)
|
||||
finisherChan := make(chan *sharedPullerState)
|
||||
dbUpdateChan := make(chan dbUpdateJob, 1)
|
||||
snap := f.fset.Snapshot()
|
||||
@@ -509,7 +490,12 @@ func TestDeregisterOnFailInCopy(t *testing.T) {
|
||||
|
||||
// Receive a block at puller, to indicate that at least a single copier
|
||||
// loop has been performed.
|
||||
toPull := <-pullChan
|
||||
var toPull pullBlockState
|
||||
select {
|
||||
case toPull = <-pullChan:
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("timed out")
|
||||
}
|
||||
|
||||
// Unblock copier
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user