Run integration tests with -race (fixes #1043)

This commit is contained in:
Jakob Borg 2014-11-29 22:17:54 +01:00
parent 7af25c785d
commit 4fdecc9b85
7 changed files with 112 additions and 41 deletions

View File

@ -44,6 +44,7 @@ var (
goos string goos string
noupgrade bool noupgrade bool
version string version string
race bool
) )
const minGoVersion = 1.3 const minGoVersion = 1.3
@ -65,8 +66,9 @@ func main() {
flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH") flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH")
flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS") 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.StringVar(&version, "version", getVersion(), "Set compiled in version string")
flag.BoolVar(&race, "race", race, "Use race detector")
flag.Parse() flag.Parse()
switch goarch { switch goarch {
@ -182,6 +184,9 @@ func install(pkg string, tags []string) {
if len(tags) > 0 { if len(tags) > 0 {
args = append(args, "-tags", strings.Join(tags, ",")) args = append(args, "-tags", strings.Join(tags, ","))
} }
if race {
args = append(args, "-race")
}
args = append(args, pkg) args = append(args, pkg)
setBuildEnv() setBuildEnv()
runPrint("go", args...) runPrint("go", args...)
@ -193,6 +198,9 @@ func build(pkg string, tags []string) {
if len(tags) > 0 { if len(tags) > 0 {
args = append(args, "-tags", strings.Join(tags, ",")) args = append(args, "-tags", strings.Join(tags, ","))
} }
if race {
args = append(args, "-race")
}
args = append(args, pkg) args = append(args, pkg)
setBuildEnv() setBuildEnv()
runPrint("go", args...) runPrint("go", args...)

View File

@ -125,7 +125,7 @@ case "${1:-default}" in
&& cp -r /tmp/syncthing syncthing \ && cp -r /tmp/syncthing syncthing \
&& cd syncthing \ && cd syncthing \
&& ./build.sh clean \ && ./build.sh clean \
&& ./build.sh \ && go run build.go -race \
&& export GOPATH=$(pwd)/Godeps/_workspace:$GOPATH \ && export GOPATH=$(pwd)/Godeps/_workspace:$GOPATH \
&& cd test \ && cd test \
&& go test -tags integration -v' && go test -tags integration -v'

View File

@ -18,6 +18,8 @@
package integration_test package integration_test
import ( import (
"bufio"
"bytes"
"crypto/md5" "crypto/md5"
"encoding/json" "encoding/json"
"errors" "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.Process.Signal(os.Interrupt)
p.cmd.Wait() 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) { func (p *syncthingProcess) get(path string) (*http.Response, error) {

View File

@ -77,7 +77,7 @@ func TestFiletypeChange(t *testing.T) {
} }
err = receiver.start() err = receiver.start()
if err != nil { if err != nil {
sender.stop() _ = sender.stop()
t.Fatal(err) t.Fatal(err)
} }
@ -88,24 +88,30 @@ func TestFiletypeChange(t *testing.T) {
time.Sleep(time.Second) time.Sleep(time.Second)
continue continue
} }
sender.stop() _ = sender.stop()
receiver.stop() _ = receiver.stop()
t.Fatal(err) t.Fatal(err)
} }
curComp := comp[id2] curComp := comp[id2]
if curComp == 100 { if curComp == 100 {
sender.stop() _ = sender.stop()
receiver.stop() _ = receiver.stop()
break break
} }
time.Sleep(time.Second) time.Sleep(time.Second)
} }
sender.stop() err = sender.stop()
receiver.stop() if err != nil {
t.Fatal(err)
}
err = receiver.stop()
if err != nil {
t.Fatal(err)
}
log.Println("Comparing directories...") log.Println("Comparing directories...")
err = compareDirectories("s1", "s2") err = compareDirectories("s1", "s2")
@ -143,7 +149,7 @@ func TestFiletypeChange(t *testing.T) {
err = receiver.start() err = receiver.start()
if err != nil { if err != nil {
sender.stop() _ = sender.stop()
t.Fatal(err) t.Fatal(err)
} }
@ -154,24 +160,28 @@ func TestFiletypeChange(t *testing.T) {
time.Sleep(time.Second) time.Sleep(time.Second)
continue continue
} }
sender.stop() _ = sender.stop()
receiver.stop() _ = receiver.stop()
t.Fatal(err) t.Fatal(err)
} }
curComp := comp[id2] curComp := comp[id2]
if curComp == 100 { if curComp == 100 {
sender.stop()
receiver.stop()
break break
} }
time.Sleep(time.Second) time.Sleep(time.Second)
} }
sender.stop() err = sender.stop()
receiver.stop() if err != nil {
t.Fatal(err)
}
err = receiver.stop()
if err != nil {
t.Fatal(err)
}
log.Println("Comparing directories...") log.Println("Comparing directories...")
err = compareDirectories("s1", "s2") err = compareDirectories("s1", "s2")

View File

@ -120,10 +120,13 @@ func TestStressHTTP(t *testing.T) {
}() }()
err = <-errChan err = <-errChan
if err != nil {
t.Error(err)
}
t.Logf("%.01f reqs/sec", float64(counter)/time.Since(t0).Seconds()) t.Logf("%.01f reqs/sec", float64(counter)/time.Since(t0).Seconds())
sender.stop() err = sender.stop()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View File

@ -73,7 +73,7 @@ func testRestartDuringTransfer(t *testing.T, restartSender, restartReceiver bool
} }
err = receiver.start() err = receiver.start()
if err != nil { if err != nil {
sender.stop() _ = sender.stop()
t.Fatal(err) t.Fatal(err)
} }
@ -85,28 +85,40 @@ func testRestartDuringTransfer(t *testing.T, restartSender, restartReceiver bool
time.Sleep(250 * time.Millisecond) time.Sleep(250 * time.Millisecond)
continue continue
} }
sender.stop() _ = sender.stop()
receiver.stop() _ = receiver.stop()
t.Fatal(err) t.Fatal(err)
} }
curComp := comp[id2] curComp := comp[id2]
if curComp == 100 { if curComp == 100 {
sender.stop() err = sender.stop()
receiver.stop() if err != nil {
t.Fatal(err)
}
err = receiver.stop()
if err != nil {
t.Fatal(err)
}
break break
} }
if curComp > prevComp { if curComp > prevComp {
if restartReceiver { if restartReceiver {
log.Printf("Stopping receiver...") log.Printf("Stopping receiver...")
receiver.stop() err = receiver.stop()
if err != nil {
t.Fatal(err)
}
} }
if restartSender { if restartSender {
log.Printf("Stopping sender...") log.Printf("Stopping sender...")
sender.stop() err = sender.stop()
if err != nil {
t.Fatal(err)
}
} }
var wg sync.WaitGroup var wg sync.WaitGroup
@ -139,8 +151,14 @@ func testRestartDuringTransfer(t *testing.T, restartSender, restartReceiver bool
time.Sleep(250 * time.Millisecond) time.Sleep(250 * time.Millisecond)
} }
sender.stop() err = sender.stop()
receiver.stop() if err != nil {
t.Fatal(err)
}
err = receiver.stop()
if err != nil {
t.Fatal(err)
}
log.Println("Comparing directories...") log.Println("Comparing directories...")
err = compareDirectories("s1", "s2") err = compareDirectories("s1", "s2")

View File

@ -122,7 +122,7 @@ func TestSymlinks(t *testing.T) {
} }
err = receiver.start() err = receiver.start()
if err != nil { if err != nil {
sender.stop() _ = sender.stop()
t.Fatal(err) t.Fatal(err)
} }
@ -133,24 +133,28 @@ func TestSymlinks(t *testing.T) {
time.Sleep(time.Second) time.Sleep(time.Second)
continue continue
} }
sender.stop() _ = sender.stop()
receiver.stop() _ = receiver.stop()
t.Fatal(err) t.Fatal(err)
} }
curComp := comp[id2] curComp := comp[id2]
if curComp == 100 { if curComp == 100 {
sender.stop()
receiver.stop()
break break
} }
time.Sleep(time.Second) time.Sleep(time.Second)
} }
sender.stop() err = sender.stop()
receiver.stop() if err != nil {
t.Fatal(err)
}
err = receiver.stop()
if err != nil {
t.Fatal(err)
}
log.Println("Comparing directories...") log.Println("Comparing directories...")
err = compareDirectories("s1", "s2") err = compareDirectories("s1", "s2")
@ -236,7 +240,7 @@ func TestSymlinks(t *testing.T) {
err = receiver.start() err = receiver.start()
if err != nil { if err != nil {
sender.stop() _ = sender.stop()
t.Fatal(err) t.Fatal(err)
} }
@ -247,24 +251,28 @@ func TestSymlinks(t *testing.T) {
time.Sleep(time.Second) time.Sleep(time.Second)
continue continue
} }
sender.stop() _ = sender.stop()
receiver.stop() _ = receiver.stop()
t.Fatal(err) t.Fatal(err)
} }
curComp := comp[id2] curComp := comp[id2]
if curComp == 100 { if curComp == 100 {
sender.stop()
receiver.stop()
break break
} }
time.Sleep(time.Second) time.Sleep(time.Second)
} }
sender.stop() err = sender.stop()
receiver.stop() if err != nil {
t.Fatal(err)
}
err = receiver.stop()
if err != nil {
t.Fatal(err)
}
log.Println("Comparing directories...") log.Println("Comparing directories...")
err = compareDirectories("s1", "s2") err = compareDirectories("s1", "s2")