manypeers_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 https://mozilla.org/MPL/2.0/.
  6. // +build integration
  7. package integration
  8. import (
  9. "bytes"
  10. "encoding/json"
  11. "log"
  12. "os"
  13. "testing"
  14. "github.com/syncthing/syncthing/lib/config"
  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. receiver.ResumeAll()
  32. bs, err := receiver.Get("/rest/system/config")
  33. if err != nil {
  34. t.Fatal(err)
  35. }
  36. var cfg config.Configuration
  37. if err := json.Unmarshal(bs, &cfg); err != nil {
  38. t.Fatal(err)
  39. }
  40. for len(cfg.Devices) < 100 {
  41. bs := make([]byte, 16)
  42. ReadRand(bs)
  43. id := protocol.NewDeviceID(bs)
  44. cfg.Devices = append(cfg.Devices, config.DeviceConfiguration{DeviceID: id})
  45. cfg.Folders[0].Devices = append(cfg.Folders[0].Devices, config.FolderDeviceConfiguration{DeviceID: id})
  46. }
  47. os.Rename("h2/config.xml", "h2/config.xml.orig")
  48. defer os.Rename("h2/config.xml.orig", "h2/config.xml")
  49. var buf bytes.Buffer
  50. json.NewEncoder(&buf).Encode(cfg)
  51. _, err = receiver.Post("/rest/system/config", &buf)
  52. if err != nil {
  53. t.Fatal(err)
  54. }
  55. sender := startInstance(t, 1)
  56. defer checkedStop(t, sender)
  57. sender.ResumeAll()
  58. rc.AwaitSync("default", sender, receiver)
  59. log.Println("Comparing directories...")
  60. err = compareDirectories("s1", "s2")
  61. if err != nil {
  62. t.Fatal(err)
  63. }
  64. }