transfer-bench_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. err = sender.start()
  46. if err != nil {
  47. t.Fatal(err)
  48. }
  49. receiver := syncthingProcess{ // id2
  50. log: "2.out",
  51. argv: []string{"-home", "h2"},
  52. port: 8082,
  53. apiKey: apiKey,
  54. }
  55. err = receiver.start()
  56. if err != nil {
  57. sender.stop()
  58. t.Fatal(err)
  59. }
  60. var t0 time.Time
  61. loop:
  62. for {
  63. evs, err := receiver.events()
  64. if err != nil {
  65. if strings.Contains(err.Error(), "use of closed network connection") {
  66. log.Println("...")
  67. continue
  68. }
  69. sender.stop()
  70. receiver.stop()
  71. t.Fatal(err)
  72. }
  73. for _, ev := range evs {
  74. if ev.Type == "StateChanged" {
  75. data := ev.Data.(map[string]interface{})
  76. if data["folder"].(string) != "default" {
  77. continue
  78. }
  79. log.Println(ev)
  80. if data["to"].(string) == "syncing" {
  81. t0 = ev.Time
  82. continue
  83. }
  84. if t0 != (time.Time{}) && data["to"].(string) == "idle" {
  85. log.Println("Sync took", ev.Time.Sub(t0))
  86. break loop
  87. }
  88. }
  89. }
  90. time.Sleep(250 * time.Millisecond)
  91. }
  92. sender.stop()
  93. receiver.stop()
  94. }