transfer-bench_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  2. //
  3. // This program is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by the Free
  5. // Software Foundation, either version 3 of the License, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but WITHOUT
  9. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. // more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program. If not, see <http://www.gnu.org/licenses/>.
  15. // +build integration
  16. package integration_test
  17. import (
  18. "log"
  19. "strings"
  20. "testing"
  21. "time"
  22. )
  23. func TestBenchmarkTransfer(t *testing.T) {
  24. nfiles := 10000
  25. if testing.Short() {
  26. nfiles = 1000
  27. }
  28. log.Println("Cleaning...")
  29. err := removeAll("s1", "s2", "h1/index", "h2/index")
  30. if err != nil {
  31. t.Fatal(err)
  32. }
  33. log.Println("Generating files...")
  34. err = generateFiles("s1", nfiles, 22, "../bin/syncthing")
  35. if err != nil {
  36. t.Fatal(err)
  37. }
  38. log.Println("Starting up...")
  39. sender := syncthingProcess{ // id1
  40. log: "1.out",
  41. argv: []string{"-home", "h1"},
  42. port: 8081,
  43. apiKey: apiKey,
  44. }
  45. ver, err := sender.start()
  46. if err != nil {
  47. t.Fatal(err)
  48. }
  49. log.Println(ver)
  50. receiver := syncthingProcess{ // id2
  51. log: "2.out",
  52. argv: []string{"-home", "h2"},
  53. port: 8082,
  54. apiKey: apiKey,
  55. }
  56. ver, err = receiver.start()
  57. if err != nil {
  58. sender.stop()
  59. t.Fatal(err)
  60. }
  61. log.Println(ver)
  62. var t0 time.Time
  63. loop:
  64. for {
  65. evs, err := receiver.events()
  66. if err != nil {
  67. if strings.Contains(err.Error(), "use of closed network connection") {
  68. log.Println("...")
  69. continue
  70. }
  71. sender.stop()
  72. receiver.stop()
  73. t.Fatal(err)
  74. }
  75. for _, ev := range evs {
  76. if ev.Type == "StateChanged" {
  77. data := ev.Data.(map[string]interface{})
  78. if data["folder"].(string) != "default" {
  79. continue
  80. }
  81. log.Println(ev)
  82. if data["to"].(string) == "syncing" {
  83. t0 = ev.Time
  84. continue
  85. }
  86. if t0 != (time.Time{}) && data["to"].(string) == "idle" {
  87. log.Println("Sync took", ev.Time.Sub(t0))
  88. break loop
  89. }
  90. }
  91. }
  92. time.Sleep(250 * time.Millisecond)
  93. }
  94. sender.stop()
  95. receiver.stop()
  96. }