parallell_scan_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. "io/ioutil"
  10. "log"
  11. "sync"
  12. "testing"
  13. "time"
  14. )
  15. func TestRescanInParallel(t *testing.T) {
  16. log.Println("Cleaning...")
  17. err := removeAll("s1", "h1/index*")
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. log.Println("Generating files...")
  22. err = generateFiles("s1", 5000, 18, "../LICENSE")
  23. if err != nil {
  24. t.Fatal(err)
  25. }
  26. log.Println("Generating .stignore...")
  27. err = ioutil.WriteFile("s1/.stignore", []byte("some ignore data\n"), 0644)
  28. if err != nil {
  29. t.Fatal(err)
  30. }
  31. st := startInstance(t, 1)
  32. defer checkedStop(t, st)
  33. var wg sync.WaitGroup
  34. log.Println("Starting scans...")
  35. for j := 0; j < 20; j++ {
  36. j := j
  37. wg.Add(1)
  38. go func() {
  39. defer wg.Done()
  40. err := st.Rescan("default")
  41. log.Println(j)
  42. if err != nil {
  43. log.Println(err)
  44. t.Fatal(err)
  45. }
  46. }()
  47. }
  48. wg.Wait()
  49. log.Println("Scans done")
  50. time.Sleep(2 * time.Second)
  51. // This is where the real test is currently, since stop() checks for data
  52. // race output in the log.
  53. log.Println("Stopping...")
  54. checkedStop(t, st)
  55. }