syncthing/test/parallell_scan_test.go

92 lines
1.7 KiB
Go
Raw Normal View History

2014-12-02 22:13:08 +01:00
// Copyright (C) 2014 The Syncthing Authors.
//
2015-03-07 21:36:35 +01:00
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
2014-12-02 22:13:08 +01:00
// +build integration
package integration
2014-12-02 22:13:08 +01:00
import (
"io/ioutil"
"log"
"sync"
"testing"
"time"
)
func TestParallellScan(t *testing.T) {
log.Println("Cleaning...")
err := removeAll("s1", "h1/index*")
2014-12-02 22:13:08 +01:00
if err != nil {
t.Fatal(err)
}
log.Println("Generating files...")
err = generateFiles("s1", 5000, 18, "../LICENSE")
if err != nil {
t.Fatal(err)
}
log.Println("Generating .stignore...")
2014-12-02 22:13:08 +01:00
err = ioutil.WriteFile("s1/.stignore", []byte("some ignore data\n"), 0644)
if err != nil {
t.Fatal(err)
}
log.Println("Starting up...")
st := syncthingProcess{ // id1
instance: "1",
argv: []string{"-home", "h1"},
port: 8081,
apiKey: apiKey,
2014-12-02 22:13:08 +01:00
}
err = st.start()
if err != nil {
t.Fatal(err)
}
// Wait for one scan to succeed, or up to 20 seconds...
// This is to let startup, UPnP etc complete.
for i := 0; i < 20; i++ {
2015-04-01 10:43:19 +02:00
err := st.rescan("default")
if err != nil {
time.Sleep(time.Second)
continue
}
break
}
// Wait for UPnP and stuff
time.Sleep(10 * time.Second)
2014-12-02 22:13:08 +01:00
var wg sync.WaitGroup
log.Println("Starting scans...")
for j := 0; j < 20; j++ {
j := j
wg.Add(1)
go func() {
defer wg.Done()
2015-04-01 10:43:19 +02:00
err := st.rescan("default")
2014-12-02 22:13:08 +01:00
log.Println(j)
if err != nil {
log.Println(err)
t.Fatal(err)
}
}()
}
wg.Wait()
log.Println("Scans done")
time.Sleep(2 * time.Second)
// This is where the real test is currently, since stop() checks for data
// race output in the log.
log.Println("Stopping...")
_, err = st.stop()
2014-12-02 22:13:08 +01:00
if err != nil {
t.Fatal(err)
}
}