manypeers_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. //go:build integration
  7. // +build integration
  8. package integration
  9. import (
  10. "bytes"
  11. "encoding/json"
  12. "log"
  13. "os"
  14. "testing"
  15. "github.com/syncthing/syncthing/lib/config"
  16. "github.com/syncthing/syncthing/lib/protocol"
  17. "github.com/syncthing/syncthing/lib/rc"
  18. )
  19. func TestManyPeers(t *testing.T) {
  20. log.Println("Cleaning...")
  21. err := removeAll("s1", "s2", "h1/index*", "h2/index*")
  22. if err != nil {
  23. t.Fatal(err)
  24. }
  25. log.Println("Generating files...")
  26. err = generateFiles("s1", 200, 20, "../LICENSE")
  27. if err != nil {
  28. t.Fatal(err)
  29. }
  30. receiver := startInstance(t, 2)
  31. defer checkedStop(t, receiver)
  32. receiver.ResumeAll()
  33. bs, err := receiver.Get("/rest/system/config")
  34. if err != nil {
  35. t.Fatal(err)
  36. }
  37. var cfg config.Configuration
  38. if err := json.Unmarshal(bs, &cfg); err != nil {
  39. t.Fatal(err)
  40. }
  41. for len(cfg.Devices) < 100 {
  42. bs := make([]byte, 16)
  43. ReadRand(bs)
  44. id := protocol.NewDeviceID(bs)
  45. cfg.Devices = append(cfg.Devices, config.DeviceConfiguration{DeviceID: id})
  46. cfg.Folders[0].Devices = append(cfg.Folders[0].Devices, config.FolderDeviceConfiguration{DeviceID: id})
  47. }
  48. os.Rename("h2/config.xml", "h2/config.xml.orig")
  49. defer os.Rename("h2/config.xml.orig", "h2/config.xml")
  50. var buf bytes.Buffer
  51. json.NewEncoder(&buf).Encode(cfg)
  52. _, err = receiver.Post("/rest/system/config", &buf)
  53. if err != nil {
  54. t.Fatal(err)
  55. }
  56. sender := startInstance(t, 1)
  57. defer checkedStop(t, sender)
  58. sender.ResumeAll()
  59. rc.AwaitSync("default", sender, receiver)
  60. log.Println("Comparing directories...")
  61. err = compareDirectories("s1", "s2")
  62. if err != nil {
  63. t.Fatal(err)
  64. }
  65. }