mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 10:58:57 +00:00
Run integration tests with -race (fixes #1043)
This commit is contained in:
parent
7af25c785d
commit
4fdecc9b85
10
build.go
10
build.go
@ -44,6 +44,7 @@ var (
|
||||
goos string
|
||||
noupgrade bool
|
||||
version string
|
||||
race bool
|
||||
)
|
||||
|
||||
const minGoVersion = 1.3
|
||||
@ -65,8 +66,9 @@ func main() {
|
||||
|
||||
flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH")
|
||||
flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS")
|
||||
flag.BoolVar(&noupgrade, "no-upgrade", false, "Disable upgrade functionality")
|
||||
flag.BoolVar(&noupgrade, "no-upgrade", noupgrade, "Disable upgrade functionality")
|
||||
flag.StringVar(&version, "version", getVersion(), "Set compiled in version string")
|
||||
flag.BoolVar(&race, "race", race, "Use race detector")
|
||||
flag.Parse()
|
||||
|
||||
switch goarch {
|
||||
@ -182,6 +184,9 @@ func install(pkg string, tags []string) {
|
||||
if len(tags) > 0 {
|
||||
args = append(args, "-tags", strings.Join(tags, ","))
|
||||
}
|
||||
if race {
|
||||
args = append(args, "-race")
|
||||
}
|
||||
args = append(args, pkg)
|
||||
setBuildEnv()
|
||||
runPrint("go", args...)
|
||||
@ -193,6 +198,9 @@ func build(pkg string, tags []string) {
|
||||
if len(tags) > 0 {
|
||||
args = append(args, "-tags", strings.Join(tags, ","))
|
||||
}
|
||||
if race {
|
||||
args = append(args, "-race")
|
||||
}
|
||||
args = append(args, pkg)
|
||||
setBuildEnv()
|
||||
runPrint("go", args...)
|
||||
|
2
build.sh
2
build.sh
@ -125,7 +125,7 @@ case "${1:-default}" in
|
||||
&& cp -r /tmp/syncthing syncthing \
|
||||
&& cd syncthing \
|
||||
&& ./build.sh clean \
|
||||
&& ./build.sh \
|
||||
&& go run build.go -race \
|
||||
&& export GOPATH=$(pwd)/Godeps/_workspace:$GOPATH \
|
||||
&& cd test \
|
||||
&& go test -tags integration -v'
|
||||
|
@ -18,6 +18,8 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@ -94,9 +96,31 @@ func (p *syncthingProcess) start() error {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *syncthingProcess) stop() {
|
||||
func (p *syncthingProcess) stop() error {
|
||||
p.cmd.Process.Signal(os.Interrupt)
|
||||
p.cmd.Wait()
|
||||
|
||||
fd, err := os.Open(p.log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
raceCondition := []byte("DATA RACE")
|
||||
sc := bufio.NewScanner(fd)
|
||||
for sc.Scan() {
|
||||
line := sc.Bytes()
|
||||
if bytes.Contains(line, raceCondition) {
|
||||
name := fmt.Sprintf("race-%d.out", time.Now().Unix())
|
||||
cp, _ := os.Create(name)
|
||||
fd.Seek(0, os.SEEK_SET)
|
||||
io.Copy(cp, fd)
|
||||
cp.Close()
|
||||
|
||||
return errors.New("Race condition detected in " + name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *syncthingProcess) get(path string) (*http.Response, error) {
|
||||
|
@ -77,7 +77,7 @@ func TestFiletypeChange(t *testing.T) {
|
||||
}
|
||||
err = receiver.start()
|
||||
if err != nil {
|
||||
sender.stop()
|
||||
_ = sender.stop()
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -88,24 +88,30 @@ func TestFiletypeChange(t *testing.T) {
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
}
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
_ = sender.stop()
|
||||
_ = receiver.stop()
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
curComp := comp[id2]
|
||||
|
||||
if curComp == 100 {
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
_ = sender.stop()
|
||||
_ = receiver.stop()
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
err = sender.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = receiver.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("Comparing directories...")
|
||||
err = compareDirectories("s1", "s2")
|
||||
@ -143,7 +149,7 @@ func TestFiletypeChange(t *testing.T) {
|
||||
|
||||
err = receiver.start()
|
||||
if err != nil {
|
||||
sender.stop()
|
||||
_ = sender.stop()
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -154,24 +160,28 @@ func TestFiletypeChange(t *testing.T) {
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
}
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
_ = sender.stop()
|
||||
_ = receiver.stop()
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
curComp := comp[id2]
|
||||
|
||||
if curComp == 100 {
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
err = sender.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = receiver.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("Comparing directories...")
|
||||
err = compareDirectories("s1", "s2")
|
||||
|
@ -120,10 +120,13 @@ func TestStressHTTP(t *testing.T) {
|
||||
}()
|
||||
|
||||
err = <-errChan
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
t.Logf("%.01f reqs/sec", float64(counter)/time.Since(t0).Seconds())
|
||||
|
||||
sender.stop()
|
||||
err = sender.stop()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ func testRestartDuringTransfer(t *testing.T, restartSender, restartReceiver bool
|
||||
}
|
||||
err = receiver.start()
|
||||
if err != nil {
|
||||
sender.stop()
|
||||
_ = sender.stop()
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -85,28 +85,40 @@ func testRestartDuringTransfer(t *testing.T, restartSender, restartReceiver bool
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
continue
|
||||
}
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
_ = sender.stop()
|
||||
_ = receiver.stop()
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
curComp := comp[id2]
|
||||
|
||||
if curComp == 100 {
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
err = sender.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = receiver.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if curComp > prevComp {
|
||||
if restartReceiver {
|
||||
log.Printf("Stopping receiver...")
|
||||
receiver.stop()
|
||||
err = receiver.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if restartSender {
|
||||
log.Printf("Stopping sender...")
|
||||
sender.stop()
|
||||
err = sender.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
@ -139,8 +151,14 @@ func testRestartDuringTransfer(t *testing.T, restartSender, restartReceiver bool
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
}
|
||||
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
err = sender.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = receiver.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("Comparing directories...")
|
||||
err = compareDirectories("s1", "s2")
|
||||
|
@ -122,7 +122,7 @@ func TestSymlinks(t *testing.T) {
|
||||
}
|
||||
err = receiver.start()
|
||||
if err != nil {
|
||||
sender.stop()
|
||||
_ = sender.stop()
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -133,24 +133,28 @@ func TestSymlinks(t *testing.T) {
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
}
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
_ = sender.stop()
|
||||
_ = receiver.stop()
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
curComp := comp[id2]
|
||||
|
||||
if curComp == 100 {
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
err = sender.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = receiver.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("Comparing directories...")
|
||||
err = compareDirectories("s1", "s2")
|
||||
@ -236,7 +240,7 @@ func TestSymlinks(t *testing.T) {
|
||||
|
||||
err = receiver.start()
|
||||
if err != nil {
|
||||
sender.stop()
|
||||
_ = sender.stop()
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -247,24 +251,28 @@ func TestSymlinks(t *testing.T) {
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
}
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
_ = sender.stop()
|
||||
_ = receiver.stop()
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
curComp := comp[id2]
|
||||
|
||||
if curComp == 100 {
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
sender.stop()
|
||||
receiver.stop()
|
||||
err = sender.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = receiver.stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("Comparing directories...")
|
||||
err = compareDirectories("s1", "s2")
|
||||
|
Loading…
Reference in New Issue
Block a user