parallell_scan_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (C) 2014 The Syncthing Authors.
  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
  17. import (
  18. "io/ioutil"
  19. "log"
  20. "sync"
  21. "testing"
  22. "time"
  23. )
  24. func TestParallellScan(t *testing.T) {
  25. log.Println("Cleaning...")
  26. err := removeAll("s1", "h1/index")
  27. if err != nil {
  28. t.Fatal(err)
  29. }
  30. log.Println("Generating files...")
  31. err = generateFiles("s1", 5000, 18, "../LICENSE")
  32. if err != nil {
  33. t.Fatal(err)
  34. }
  35. log.Println("Generaing .stignore...")
  36. err = ioutil.WriteFile("s1/.stignore", []byte("some ignore data\n"), 0644)
  37. if err != nil {
  38. t.Fatal(err)
  39. }
  40. log.Println("Starting up...")
  41. st := syncthingProcess{ // id1
  42. instance: "1",
  43. argv: []string{"-home", "h1"},
  44. port: 8081,
  45. apiKey: apiKey,
  46. }
  47. err = st.start()
  48. if err != nil {
  49. t.Fatal(err)
  50. }
  51. time.Sleep(5 * time.Second)
  52. var wg sync.WaitGroup
  53. log.Println("Starting scans...")
  54. for j := 0; j < 20; j++ {
  55. j := j
  56. wg.Add(1)
  57. go func() {
  58. defer wg.Done()
  59. resp, err := st.post("/rest/scan?folder=default", nil)
  60. log.Println(j)
  61. if err != nil {
  62. log.Println(err)
  63. t.Fatal(err)
  64. }
  65. if resp.StatusCode != 200 {
  66. t.Fatalf("%d != 200", resp.StatusCode)
  67. }
  68. resp.Body.Close()
  69. }()
  70. }
  71. wg.Wait()
  72. log.Println("Scans done")
  73. time.Sleep(2 * time.Second)
  74. // This is where the real test is currently, since stop() checks for data
  75. // race output in the log.
  76. log.Println("Stopping...")
  77. err = st.stop()
  78. if err != nil {
  79. t.Fatal(err)
  80. }
  81. }