Permalink
Browse files

get tests closer to reality

  • Loading branch information...
imsodin committed Jan 31, 2019
1 parent 18d2e08 commit 8edd19b05a2a1dc6e5d1d0c8b3b98c331976217e
Showing with 206 additions and 234 deletions.
  1. +27 −17 lib/model/model.go
  2. +89 −148 lib/model/model_test.go
  3. +84 −62 lib/model/requests_test.go
  4. +6 −7 lib/model/sharedpullerstate_test.go
@@ -2150,11 +2150,36 @@ func (m *Model) numHashers(folder string) int {
// generateClusterConfig returns a ClusterConfigMessage that is correct for
// the given peer device
func (m *Model) generateClusterConfig(device protocol.DeviceID) protocol.ClusterConfig {
var message protocol.ClusterConfig

m.fmut.RLock()
defer m.fmut.RUnlock()

message := m.generateClusterConfigWithoutSeqs(device)

for i, folder := range message.Folders {
if folder.Paused {
continue
}

fs := m.folderFiles[folder.ID]

for j := range folder.Devices {
id := folder.Devices[j].ID
if id == m.id {
message.Folders[i].Devices[j].IndexID = fs.IndexID(protocol.LocalDeviceID)
message.Folders[i].Devices[j].MaxSequence = fs.Sequence(protocol.LocalDeviceID)
} else {
message.Folders[i].Devices[j].IndexID = fs.IndexID(id)
message.Folders[i].Devices[j].MaxSequence = fs.Sequence(id)
}
}
}

return message
}

func (m *Model) generateClusterConfigWithoutSeqs(device protocol.DeviceID) protocol.ClusterConfig {
var message protocol.ClusterConfig

for _, folderCfg := range m.cfg.FolderList() {
if !folderCfg.SharedWith(device) {
continue
@@ -2170,11 +2195,6 @@ func (m *Model) generateClusterConfig(device protocol.DeviceID) protocol.Cluster
Paused: folderCfg.Paused,
}

var fs *db.FileSet
if !folderCfg.Paused {
fs = m.folderFiles[folderCfg.ID]
}

for _, device := range folderCfg.Devices {
deviceCfg, _ := m.cfg.Device(device.DeviceID)

@@ -2187,16 +2207,6 @@ func (m *Model) generateClusterConfig(device protocol.DeviceID) protocol.Cluster
Introducer: deviceCfg.Introducer,
}

if fs != nil {
if deviceCfg.DeviceID == m.id {
protocolDevice.IndexID = fs.IndexID(protocol.LocalDeviceID)
protocolDevice.MaxSequence = fs.Sequence(protocol.LocalDeviceID)
} else {
protocolDevice.IndexID = fs.IndexID(deviceCfg.DeviceID)
protocolDevice.MaxSequence = fs.Sequence(deviceCfg.DeviceID)
}
}

protocolFolder.Devices = append(protocolFolder.Devices, protocolDevice)
}

Oops, something went wrong.

0 comments on commit 8edd19b

Please sign in to comment.