manypeers_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at http://mozilla.org/MPL/2.0/.
  6. // +build integration
  7. package integration
  8. import (
  9. "bytes"
  10. "encoding/json"
  11. "log"
  12. "testing"
  13. "github.com/syncthing/syncthing/lib/config"
  14. "github.com/syncthing/syncthing/lib/osutil"
  15. "github.com/syncthing/syncthing/lib/protocol"
  16. "github.com/syncthing/syncthing/lib/rc"
  17. )
  18. func TestManyPeers(t *testing.T) {
  19. log.Println("Cleaning...")
  20. err := removeAll("s1", "s2", "h1/index*", "h2/index*")
  21. if err != nil {
  22. t.Fatal(err)
  23. }
  24. log.Println("Generating files...")
  25. err = generateFiles("s1", 200, 20, "../LICENSE")
  26. if err != nil {
  27. t.Fatal(err)
  28. }
  29. receiver := startInstance(t, 2)
  30. defer checkedStop(t, receiver)
  31. bs, err := receiver.Get("/rest/system/config")
  32. if err != nil {
  33. t.Fatal(err)
  34. }
  35. var cfg config.Configuration
  36. if err := json.Unmarshal(bs, &cfg); err != nil {
  37. t.Fatal(err)
  38. }
  39. for len(cfg.Devices) < 100 {
  40. bs := make([]byte, 16)
  41. ReadRand(bs)
  42. id := protocol.NewDeviceID(bs)
  43. cfg.Devices = append(cfg.Devices, config.DeviceConfiguration{DeviceID: id})
  44. cfg.Folders[0].Devices = append(cfg.Folders[0].Devices, config.FolderDeviceConfiguration{DeviceID: id})
  45. }
  46. osutil.Rename("h2/config.xml", "h2/config.xml.orig")
  47. defer osutil.Rename("h2/config.xml.orig", "h2/config.xml")
  48. var buf bytes.Buffer
  49. json.NewEncoder(&buf).Encode(cfg)
  50. _, err = receiver.Post("/rest/system/config", &buf)
  51. if err != nil {
  52. t.Fatal(err)
  53. }
  54. sender := startInstance(t, 1)
  55. defer checkedStop(t, sender)
  56. rc.AwaitSync("default", sender, receiver)
  57. log.Println("Comparing directories...")
  58. err = compareDirectories("s1", "s2")
  59. if err != nil {
  60. t.Fatal(err)
  61. }
  62. }