lib/model: Don't use LocalDeviceID as normal id in tests (#5512)

This commit is contained in:
Simon Frei 2019-02-06 09:32:03 +01:00 committed by Jakob Borg
parent b076031bfa
commit 2f415d8f09
4 changed files with 98 additions and 123 deletions

View File

@ -337,7 +337,7 @@ func setupKnownFiles(t *testing.T, data []byte) []protocol.FileInfo {
}
func setupROFolder() *Model {
fcfg := config.NewFolderConfiguration(protocol.LocalDeviceID, "ro", "receive only test", fs.FilesystemTypeBasic, "_recvonly")
fcfg := config.NewFolderConfiguration(myID, "ro", "receive only test", fs.FilesystemTypeBasic, "_recvonly")
fcfg.Type = config.FolderTypeReceiveOnly
fcfg.Devices = []config.FolderDeviceConfiguration{{DeviceID: device1}}
fcfg.FSWatcherEnabled = false
@ -349,7 +349,7 @@ func setupROFolder() *Model {
wrp := config.Wrap("/dev/null", cfg)
db := db.OpenMemory()
m := NewModel(wrp, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(wrp, myID, "syncthing", "dev", db, nil)
m.ServeBackground()
m.AddFolder(fcfg)

View File

@ -77,7 +77,7 @@ func setUpFile(filename string, blockNumbers []int) protocol.FileInfo {
func setUpModel(files ...protocol.FileInfo) *Model {
db := db.OpenMemory()
model := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
model := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
model.AddFolder(defaultFolderConfig)
// Update index
model.updateLocalsFromScanning("default", files)
@ -408,7 +408,7 @@ func TestCopierCleanup(t *testing.T) {
m := setUpModel(file)
file.Blocks = []protocol.BlockInfo{blocks[1]}
file.Version = file.Version.Update(protocol.LocalDeviceID.Short())
file.Version = file.Version.Update(myID.Short())
// Update index (removing old blocks)
m.updateLocalsFromScanning("default", []protocol.FileInfo{file})
@ -421,7 +421,7 @@ func TestCopierCleanup(t *testing.T) {
}
file.Blocks = []protocol.BlockInfo{blocks[0]}
file.Version = file.Version.Update(protocol.LocalDeviceID.Short())
file.Version = file.Version.Update(myID.Short())
// Update index (removing old blocks)
m.updateLocalsFromScanning("default", []protocol.FileInfo{file})
@ -442,7 +442,7 @@ func TestDeregisterOnFailInCopy(t *testing.T) {
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(defaultFolderConfig)
// Set up our evet subscription early
@ -535,7 +535,7 @@ func TestDeregisterOnFailInPull(t *testing.T) {
defer testOs.Remove("testdata/" + fs.TempName("filex"))
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(defaultFolderConfig)
// Set up our evet subscription early

View File

@ -36,7 +36,7 @@ import (
"github.com/syncthing/syncthing/lib/versioner"
)
var device1, device2 protocol.DeviceID
var myID, device1, device2 protocol.DeviceID
var defaultCfgWrapper *config.Wrapper
var defaultFolderConfig config.FolderConfiguration
var defaultFs fs.Filesystem
@ -45,17 +45,25 @@ var defaultAutoAcceptCfg config.Configuration
var tmpLocation string
func init() {
myID, _ = protocol.DeviceIDFromString("ZNWFSWE-RWRV2BD-45BLMCV-LTDE2UR-4LJDW6J-R5BPWEB-TXD27XJ-IZF5RA4")
device1, _ = protocol.DeviceIDFromString("AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR")
device2, _ = protocol.DeviceIDFromString("GYRZZQB-IRNPV4Z-T7TC52W-EQYJ3TT-FDQW6MW-DFLMU42-SSSU6EM-FBK2VAY")
defaultFs = fs.NewFilesystem(fs.FilesystemTypeBasic, "testdata")
defaultFolderConfig = config.NewFolderConfiguration(protocol.LocalDeviceID, "default", "default", fs.FilesystemTypeBasic, "testdata")
defaultFolderConfig.Devices = []config.FolderDeviceConfiguration{{DeviceID: device1}}
defaultFolderConfig = config.NewFolderConfiguration(myID, "default", "default", fs.FilesystemTypeBasic, "testdata")
defaultFolderConfig.Devices = []config.FolderDeviceConfiguration{
{DeviceID: myID},
{DeviceID: device1},
}
defaultFolderConfig.FSWatcherEnabled = false
defaultCfg = config.Configuration{
Version: config.CurrentVersion,
Folders: []config.FolderConfiguration{defaultFolderConfig},
Devices: []config.DeviceConfiguration{config.NewDeviceConfiguration(device1, "device1")},
Devices: []config.DeviceConfiguration{
config.NewDeviceConfiguration(myID, "myID"),
config.NewDeviceConfiguration(device1, "device1"),
},
Options: config.OptionsConfiguration{
// Don't remove temporaries directly on startup
KeepTemporariesH: 1,
@ -64,7 +72,7 @@ func init() {
defaultAutoAcceptCfg = config.Configuration{
Devices: []config.DeviceConfiguration{
{
DeviceID: protocol.LocalDeviceID, // self
DeviceID: myID, // self
},
{
DeviceID: device1,
@ -158,7 +166,7 @@ func newState(cfg config.Configuration) (*config.Wrapper, *Model) {
wcfg := createTmpWrapper(cfg)
m := NewModel(wcfg, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(wcfg, myID, "syncthing", "dev", db, nil)
for _, folder := range cfg.Folders {
if !folder.Paused {
m.AddFolder(folder)
@ -176,7 +184,7 @@ func newState(cfg config.Configuration) (*config.Wrapper, *Model) {
func TestRequest(t *testing.T) {
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
// device1 shares default, but device2 doesn't
m.AddFolder(defaultFolderConfig)
@ -252,7 +260,7 @@ func BenchmarkIndex_100(b *testing.B) {
func benchmarkIndex(b *testing.B, nfiles int) {
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
m.ServeBackground()
@ -282,7 +290,7 @@ func BenchmarkIndexUpdate_10000_1(b *testing.B) {
func benchmarkIndexUpdate(b *testing.B, nfiles, nufiles int) {
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
m.ServeBackground()
@ -488,7 +496,7 @@ func (f *fakeConnection) sendIndexUpdate() {
func BenchmarkRequestOut(b *testing.B) {
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(defaultFolderConfig)
m.ServeBackground()
defer m.Stop()
@ -520,7 +528,7 @@ func BenchmarkRequestInSingleFile(b *testing.B) {
testOs := &fatalOs{b}
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(defaultFolderConfig)
m.ServeBackground()
defer m.Stop()
@ -562,7 +570,7 @@ func TestDeviceRename(t *testing.T) {
cfg := config.Wrap("testdata/tmpconfig.xml", rawCfg)
db := db.OpenMemory()
m := NewModel(cfg, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(cfg, myID, "syncthing", "dev", db, nil)
if cfg.Devices()[device1].Name != "" {
t.Errorf("Device already has a name")
@ -595,7 +603,7 @@ func TestDeviceRename(t *testing.T) {
t.Errorf("Device name got overwritten")
}
cfgw, err := config.Load("testdata/tmpconfig.xml", protocol.LocalDeviceID)
cfgw, err := config.Load("testdata/tmpconfig.xml", myID)
if err != nil {
t.Error(err)
return
@ -663,7 +671,7 @@ func TestClusterConfig(t *testing.T) {
wrapper := createTmpWrapper(cfg)
defer testOs.Remove(wrapper.ConfigPath())
m := NewModel(wrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(wrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(cfg.Folders[0])
m.AddFolder(cfg.Folders[1])
m.ServeBackground()
@ -1067,7 +1075,7 @@ func TestIntroducer(t *testing.T) {
Path: "testdata",
Devices: []config.FolderDeviceConfiguration{
{DeviceID: device1},
{DeviceID: device2, IntroducedBy: protocol.LocalDeviceID},
{DeviceID: device2, IntroducedBy: myID},
},
},
},
@ -1313,7 +1321,7 @@ func TestAutoAcceptNewFolderPremutationsNoPanic(t *testing.T) {
for _, dev2folder := range premutations {
cfg := defaultAutoAcceptCfg.Copy()
if localFolder.Label != "" {
fcfg := config.NewFolderConfiguration(protocol.LocalDeviceID, localFolder.ID, localFolder.Label, fs.FilesystemTypeBasic, localFolder.ID)
fcfg := config.NewFolderConfiguration(myID, localFolder.ID, localFolder.Label, fs.FilesystemTypeBasic, localFolder.ID)
fcfg.Paused = localFolderPaused
cfg.Folders = append(cfg.Folders, fcfg)
}
@ -1559,7 +1567,7 @@ func TestAutoAcceptPausedWhenFolderConfigChanged(t *testing.T) {
defer testOs.RemoveAll(idOther)
tcfg := defaultAutoAcceptCfg.Copy()
fcfg := config.NewFolderConfiguration(protocol.LocalDeviceID, id, "", fs.FilesystemTypeBasic, idOther)
fcfg := config.NewFolderConfiguration(myID, id, "", fs.FilesystemTypeBasic, idOther)
fcfg.Paused = true
// The order of devices here is wrong (cfg.clean() sorts them), which will cause the folder to restart.
// Because of the restart, folder gets removed from m.deviceFolder, which means that generateClusterConfig will not panic.
@ -1615,7 +1623,7 @@ func TestAutoAcceptPausedWhenFolderConfigNotChanged(t *testing.T) {
defer testOs.RemoveAll(idOther)
tcfg := defaultAutoAcceptCfg.Copy()
fcfg := config.NewFolderConfiguration(protocol.LocalDeviceID, id, "", fs.FilesystemTypeBasic, idOther)
fcfg := config.NewFolderConfiguration(myID, id, "", fs.FilesystemTypeBasic, idOther)
fcfg.Paused = true
// The new folder is exactly the same as the one constructed by handleAutoAccept, which means
// the folder will not be restarted (even if it's paused), yet handleAutoAccept used to add the folder
@ -1733,7 +1741,7 @@ func TestIgnores(t *testing.T) {
ioutil.WriteFile("testdata/.stignore", []byte(".*\nquux\n"), 0644)
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
m.ServeBackground()
defer m.Stop()
@ -1823,7 +1831,7 @@ func TestROScanRecovery(t *testing.T) {
testOs.RemoveAll(fcfg.Path)
m := NewModel(cfg, protocol.LocalDeviceID, "syncthing", "dev", ldb, nil)
m := NewModel(cfg, myID, "syncthing", "dev", ldb, nil)
m.AddFolder(fcfg)
m.StartFolder("default")
m.ServeBackground()
@ -1910,7 +1918,7 @@ func TestRWScanRecovery(t *testing.T) {
testOs.RemoveAll(fcfg.Path)
m := NewModel(cfg, protocol.LocalDeviceID, "syncthing", "dev", ldb, nil)
m := NewModel(cfg, myID, "syncthing", "dev", ldb, nil)
m.AddFolder(fcfg)
m.StartFolder("default")
m.ServeBackground()
@ -1968,7 +1976,7 @@ func TestRWScanRecovery(t *testing.T) {
func TestGlobalDirectoryTree(t *testing.T) {
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(defaultFolderConfig)
m.ServeBackground()
defer m.Stop()
@ -2220,7 +2228,7 @@ func TestGlobalDirectoryTree(t *testing.T) {
func TestGlobalDirectorySelfFixing(t *testing.T) {
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(defaultFolderConfig)
m.ServeBackground()
@ -2395,7 +2403,7 @@ func BenchmarkTree_100_10(b *testing.B) {
func benchmarkTree(b *testing.B, n1, n2 int) {
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(defaultFolderConfig)
m.ServeBackground()
@ -2428,7 +2436,7 @@ func TestIssue3028(t *testing.T) {
// Create a model and default folder
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
defCfg := defaultFolderConfig.Copy()
defCfg.RescanIntervalS = 86400
m.AddFolder(defCfg)
@ -2476,7 +2484,7 @@ func TestIssue4357(t *testing.T) {
// Create a separate wrapper not to pollute other tests.
wrapper := createTmpWrapper(config.Configuration{})
defer testOs.Remove(wrapper.ConfigPath())
m := NewModel(wrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(wrapper, myID, "syncthing", "dev", db, nil)
m.ServeBackground()
defer m.Stop()
@ -2582,8 +2590,8 @@ func TestIssue2782(t *testing.T) {
defer testOs.RemoveAll(testDir)
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m.AddFolder(config.NewFolderConfiguration(protocol.LocalDeviceID, "default", "default", fs.FilesystemTypeBasic, "~/"+testName+"/synclink/"))
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(config.NewFolderConfiguration(myID, "default", "default", fs.FilesystemTypeBasic, "~/"+testName+"/synclink/"))
m.StartFolder("default")
m.ServeBackground()
defer m.Stop()
@ -2613,7 +2621,7 @@ func TestIndexesForUnknownDevicesDropped(t *testing.T) {
t.Error("expected two devices")
}
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", dbi, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", dbi, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
@ -2630,27 +2638,14 @@ func TestSharedWithClearedOnDisconnect(t *testing.T) {
dbi := db.OpenMemory()
fcfg := config.NewFolderConfiguration(protocol.LocalDeviceID, "default", "default", fs.FilesystemTypeBasic, "testdata")
fcfg.Devices = []config.FolderDeviceConfiguration{
{DeviceID: device1},
{DeviceID: device2},
}
cfg := config.Configuration{
Folders: []config.FolderConfiguration{fcfg},
Devices: []config.DeviceConfiguration{
config.NewDeviceConfiguration(device1, "device1"),
config.NewDeviceConfiguration(device2, "device2"),
},
Options: config.OptionsConfiguration{
// Don't remove temporaries directly on startup
KeepTemporariesH: 1,
},
}
wcfg := createTmpWrapper(cfg)
wcfg := createTmpWrapper(defaultCfg)
wcfg.SetDevice(config.NewDeviceConfiguration(device2, "device2"))
fcfg := wcfg.FolderList()[0]
fcfg.Devices = append(fcfg.Devices, config.FolderDeviceConfiguration{DeviceID: device2})
wcfg.SetFolder(fcfg)
defer testOs.Remove(wcfg.ConfigPath())
m := NewModel(wcfg, protocol.LocalDeviceID, "syncthing", "dev", dbi, nil)
m := NewModel(wcfg, myID, "syncthing", "dev", dbi, nil)
m.AddFolder(fcfg)
m.StartFolder(fcfg.ID)
m.ServeBackground()
@ -2665,6 +2660,7 @@ func TestSharedWithClearedOnDisconnect(t *testing.T) {
{
ID: "default",
Devices: []protocol.Device{
{ID: myID},
{ID: device1},
{ID: device2},
},
@ -2676,6 +2672,7 @@ func TestSharedWithClearedOnDisconnect(t *testing.T) {
{
ID: "default",
Devices: []protocol.Device{
{ID: myID},
{ID: device1},
{ID: device2},
},
@ -2694,10 +2691,7 @@ func TestSharedWithClearedOnDisconnect(t *testing.T) {
t.Error("conn already closed")
}
cfg = cfg.Copy()
cfg.Devices = cfg.Devices[:1]
if _, err := wcfg.Replace(cfg); err != nil {
if _, err := wcfg.RemoveDevice(device2); err != nil {
t.Error(err)
}
@ -2762,7 +2756,7 @@ func TestIssue3496(t *testing.T) {
// checks on the completion calculation stuff.
dbi := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", dbi, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", dbi, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
m.ServeBackground()
@ -2835,7 +2829,7 @@ func TestIssue3496(t *testing.T) {
func TestIssue3804(t *testing.T) {
dbi := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", dbi, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", dbi, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
m.ServeBackground()
@ -2850,7 +2844,7 @@ func TestIssue3804(t *testing.T) {
func TestIssue3829(t *testing.T) {
dbi := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", dbi, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", dbi, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
m.ServeBackground()
@ -2870,27 +2864,14 @@ func TestNoRequestsFromPausedDevices(t *testing.T) {
dbi := db.OpenMemory()
fcfg := config.NewFolderConfiguration(protocol.LocalDeviceID, "default", "default", fs.FilesystemTypeBasic, "testdata")
fcfg.Devices = []config.FolderDeviceConfiguration{
{DeviceID: device1},
{DeviceID: device2},
}
cfg := config.Configuration{
Folders: []config.FolderConfiguration{fcfg},
Devices: []config.DeviceConfiguration{
config.NewDeviceConfiguration(device1, "device1"),
config.NewDeviceConfiguration(device2, "device2"),
},
Options: config.OptionsConfiguration{
// Don't remove temporaries directly on startup
KeepTemporariesH: 1,
},
}
wcfg := createTmpWrapper(cfg)
wcfg := createTmpWrapper(defaultCfg)
wcfg.SetDevice(config.NewDeviceConfiguration(device2, "device2"))
fcfg := wcfg.FolderList()[0]
fcfg.Devices = append(fcfg.Devices, config.FolderDeviceConfiguration{DeviceID: device2})
wcfg.SetFolder(fcfg)
defer testOs.Remove(wcfg.ConfigPath())
m := NewModel(wcfg, protocol.LocalDeviceID, "syncthing", "dev", dbi, nil)
m := NewModel(wcfg, myID, "syncthing", "dev", dbi, nil)
m.AddFolder(fcfg)
m.StartFolder(fcfg.ID)
m.ServeBackground()
@ -2988,7 +2969,7 @@ func TestIssue2571(t *testing.T) {
}
dbi := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", dbi, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", dbi, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
m.ServeBackground()
@ -3040,7 +3021,7 @@ func TestIssue4573(t *testing.T) {
fd.Close()
dbi := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", dbi, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", dbi, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
m.ServeBackground()
@ -3109,7 +3090,7 @@ func TestInternalScan(t *testing.T) {
}
dbi := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", dbi, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", dbi, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
m.ServeBackground()
@ -3168,7 +3149,7 @@ func TestCustomMarkerName(t *testing.T) {
testOs.RemoveAll(fcfg.Path)
defer testOs.RemoveAll(fcfg.Path)
m := NewModel(cfg, protocol.LocalDeviceID, "syncthing", "dev", ldb, nil)
m := NewModel(cfg, myID, "syncthing", "dev", ldb, nil)
m.AddFolder(fcfg)
m.StartFolder("default")
m.ServeBackground()
@ -3220,7 +3201,7 @@ func TestRemoveDirWithContent(t *testing.T) {
fd.Close()
dbi := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", dbi, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", dbi, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
m.ServeBackground()
@ -3285,7 +3266,7 @@ func TestIssue4475(t *testing.T) {
}
dbi := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", dbi, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", dbi, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
m.ServeBackground()
@ -3361,7 +3342,7 @@ func TestVersionRestore(t *testing.T) {
dbi := db.OpenMemory()
fcfg := config.NewFolderConfiguration(protocol.LocalDeviceID, "default", "default", fs.FilesystemTypeBasic, dir)
fcfg := config.NewFolderConfiguration(myID, "default", "default", fs.FilesystemTypeBasic, dir)
fcfg.Versioning.Type = "simple"
fcfg.FSWatcherEnabled = false
filesystem := fcfg.Filesystem()
@ -3372,7 +3353,7 @@ func TestVersionRestore(t *testing.T) {
cfg := createTmpWrapper(rawConfig)
defer testOs.Remove(cfg.ConfigPath())
m := NewModel(cfg, protocol.LocalDeviceID, "syncthing", "dev", dbi, nil)
m := NewModel(cfg, myID, "syncthing", "dev", dbi, nil)
m.AddFolder(fcfg)
m.StartFolder("default")
m.ServeBackground()
@ -3569,7 +3550,7 @@ func TestPausedFolders(t *testing.T) {
defer testOs.Remove(wrapper.ConfigPath())
db := db.OpenMemory()
m := NewModel(wrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(wrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
m.ServeBackground()
@ -3603,7 +3584,7 @@ func TestIssue4094(t *testing.T) {
// Create a separate wrapper not to pollute other tests.
wrapper := createTmpWrapper(config.Configuration{})
defer testOs.Remove(wrapper.ConfigPath())
m := NewModel(wrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(wrapper, myID, "syncthing", "dev", db, nil)
m.ServeBackground()
defer m.Stop()
@ -3642,7 +3623,7 @@ func TestIssue4903(t *testing.T) {
// Create a separate wrapper not to pollute other tests.
wrapper := createTmpWrapper(config.Configuration{})
defer testOs.Remove(wrapper.ConfigPath())
m := NewModel(wrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(wrapper, myID, "syncthing", "dev", db, nil)
m.ServeBackground()
defer m.Stop()
@ -3678,7 +3659,7 @@ func TestIssue5002(t *testing.T) {
// recheckFile should not panic when given an index equal to the number of blocks
db := db.OpenMemory()
m := NewModel(defaultCfgWrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(defaultCfgWrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(defaultFolderConfig)
m.StartFolder("default")
@ -3728,8 +3709,8 @@ func addFakeConn(m *Model, dev protocol.DeviceID) *fakeConnection {
{
ID: "default",
Devices: []protocol.Device{
{ID: myID},
{ID: device1},
{ID: device2},
},
},
},
@ -3750,7 +3731,7 @@ func TestFolderRestartZombies(t *testing.T) {
wrapper.SetFolder(folderCfg)
db := db.OpenMemory()
m := NewModel(wrapper, protocol.LocalDeviceID, "syncthing", "dev", db, nil)
m := NewModel(wrapper, myID, "syncthing", "dev", db, nil)
m.AddFolder(folderCfg)
m.StartFolder("default")
@ -3841,27 +3822,24 @@ func (c *alwaysChanged) Changed() bool {
func TestRequestLimit(t *testing.T) {
testOs := &fatalOs{t}
cfg := defaultCfg.Copy()
cfg.Devices = append(cfg.Devices, config.NewDeviceConfiguration(device2, "device2"))
cfg.Devices[1].MaxRequestKiB = 1
cfg.Folders[0].Devices = []config.FolderDeviceConfiguration{
{DeviceID: device1},
{DeviceID: device2},
}
m, _, wrapper := setupModelWithConnectionManual(cfg)
wrapper := createTmpWrapper(defaultCfg.Copy())
dev, _ := wrapper.Device(device1)
dev.MaxRequestKiB = 1
wrapper.SetDevice(dev)
m, _, wrapper := setupModelWithConnectionManual(wrapper.RawCopy())
defer m.Stop()
defer testOs.Remove(wrapper.ConfigPath())
file := "tmpfile"
befReq := time.Now()
first, err := m.Request(device2, "default", file, 2000, 0, nil, 0, false)
first, err := m.Request(device1, "default", file, 2000, 0, nil, 0, false)
if err != nil {
t.Fatalf("First request failed: %v", err)
}
reqDur := time.Since(befReq)
returned := make(chan struct{})
go func() {
second, err := m.Request(device2, "default", file, 2000, 0, nil, 0, false)
second, err := m.Request(device1, "default", file, 2000, 0, nil, 0, false)
if err != nil {
t.Fatalf("Second request failed: %v", err)
}

View File

@ -244,11 +244,10 @@ func TestRequestVersioningSymlinkAttack(t *testing.T) {
defer testOs.RemoveAll(tmpDir)
cfg := defaultCfgWrapper.RawCopy()
cfg.Devices = append(cfg.Devices, config.NewDeviceConfiguration(device2, "device2"))
cfg.Folders[0] = config.NewFolderConfiguration(protocol.LocalDeviceID, "default", "default", fs.FilesystemTypeBasic, tmpDir)
cfg.Folders[0] = config.NewFolderConfiguration(myID, "default", "default", fs.FilesystemTypeBasic, tmpDir)
cfg.Folders[0].Devices = []config.FolderDeviceConfiguration{
{DeviceID: myID},
{DeviceID: device1},
{DeviceID: device2},
}
cfg.Folders[0].Versioning = config.VersioningConfiguration{
Type: "trashcan",
@ -257,7 +256,7 @@ func TestRequestVersioningSymlinkAttack(t *testing.T) {
defer testOs.Remove(w.ConfigPath())
db := db.OpenMemory()
m := NewModel(w, device1, "syncthing", "dev", db, nil)
m := NewModel(w, myID, "syncthing", "dev", db, nil)
m.AddFolder(cfg.Folders[0])
m.ServeBackground()
m.StartFolder("default")
@ -265,7 +264,7 @@ func TestRequestVersioningSymlinkAttack(t *testing.T) {
defer testOs.RemoveAll(tmpDir)
fc := addFakeConn(m, device2)
fc := addFakeConn(m, device1)
fc.folder = "default"
// Create a temporary directory that we will use as target to see if
@ -333,11 +332,10 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
tmpDir := createTmpDir()
cfg := defaultCfgWrapper.RawCopy()
cfg.Devices = append(cfg.Devices, config.NewDeviceConfiguration(device2, "device2"))
cfg.Folders[0] = config.NewFolderConfiguration(protocol.LocalDeviceID, "default", "default", fs.FilesystemTypeBasic, tmpDir)
cfg.Folders[0] = config.NewFolderConfiguration(myID, "default", "default", fs.FilesystemTypeBasic, tmpDir)
cfg.Folders[0].Devices = []config.FolderDeviceConfiguration{
{DeviceID: myID},
{DeviceID: device1},
{DeviceID: device2},
}
cfg.Folders[0].Type = ft
m, fc, w := setupModelWithConnectionManual(cfg)
@ -423,7 +421,7 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
}
// The unignored files should only have a local version,
// to mark them as in conflict with any other existing versions.
ev := protocol.Vector{}.Update(device1.Short())
ev := protocol.Vector{}.Update(myID.Short())
if v := f.Version; !v.Equal(ev) {
t.Errorf("File %v has version %v, expected %v", f.Name, v, ev)
}
@ -489,7 +487,7 @@ func TestIssue4841(t *testing.T) {
Name: "foo",
Type: protocol.FileInfoTypeFile,
LocalFlags: protocol.FlagLocalIgnored,
Version: protocol.Vector{}.Update(device2.Short()),
Version: protocol.Vector{}.Update(device1.Short()),
}})
<-received
@ -499,7 +497,7 @@ func TestIssue4841(t *testing.T) {
}
f := <-received
if expected := (protocol.Vector{}.Update(device1.Short())); !f.Version.Equal(expected) {
if expected := (protocol.Vector{}.Update(myID.Short())); !f.Version.Equal(expected) {
t.Errorf("Got Version == %v, expected %v", f.Version, expected)
}
}
@ -543,7 +541,7 @@ func TestRescanIfHaveInvalidContent(t *testing.T) {
t.Fatalf("unexpected weak hash: %d != 103547413", f.Blocks[0].WeakHash)
}
res, err := m.Request(device2, "default", "foo", int32(len(payload)), 0, f.Blocks[0].Hash, f.Blocks[0].WeakHash, false)
res, err := m.Request(device1, "default", "foo", int32(len(payload)), 0, f.Blocks[0].Hash, f.Blocks[0].WeakHash, false)
if err != nil {
t.Fatal(err)
}
@ -559,7 +557,7 @@ func TestRescanIfHaveInvalidContent(t *testing.T) {
t.Fatal(err)
}
_, err = m.Request(device2, "default", "foo", int32(len(payload)), 0, f.Blocks[0].Hash, f.Blocks[0].WeakHash, false)
_, err = m.Request(device1, "default", "foo", int32(len(payload)), 0, f.Blocks[0].Hash, f.Blocks[0].WeakHash, false)
if err == nil {
t.Fatalf("expected failure")
}
@ -728,12 +726,11 @@ func TestRequestSymlinkWindows(t *testing.T) {
func setupModelWithConnection() (*Model, *fakeConnection, string, *config.Wrapper) {
tmpDir := createTmpDir()
cfg := defaultCfgWrapper.RawCopy()
cfg.Devices = append(cfg.Devices, config.NewDeviceConfiguration(device2, "device2"))
cfg.Folders[0] = config.NewFolderConfiguration(protocol.LocalDeviceID, "default", "default", fs.FilesystemTypeBasic, tmpDir)
cfg.Folders[0] = config.NewFolderConfiguration(myID, "default", "default", fs.FilesystemTypeBasic, tmpDir)
cfg.Folders[0].FSWatcherEnabled = false
cfg.Folders[0].Devices = []config.FolderDeviceConfiguration{
{DeviceID: myID},
{DeviceID: device1},
{DeviceID: device2},
}
m, fc, w := setupModelWithConnectionManual(cfg)
return m, fc, tmpDir, w
@ -743,12 +740,12 @@ func setupModelWithConnectionManual(cfg config.Configuration) (*Model, *fakeConn
w := createTmpWrapper(cfg)
db := db.OpenMemory()
m := NewModel(w, device1, "syncthing", "dev", db, nil)
m := NewModel(w, myID, "syncthing", "dev", db, nil)
m.AddFolder(cfg.Folders[0])
m.ServeBackground()
m.StartFolder("default")
fc := addFakeConn(m, device2)
fc := addFakeConn(m, device1)
fc.folder = "default"
m.ScanFolder("default")