Skip to content

Commit

Permalink
start ab after compilation is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
fvbock committed Sep 30, 2015
1 parent 77b9860 commit d13ee2c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions test/test_restarting.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
keepRestarting bool
)

func compileAndStartTestServer() {
func compileAndStartTestServer(compileDone chan struct{}) {
cmd := exec.Command("go", []string{"build", "-a", "-v", "-o", "test_server", "examples/testserver.go"}...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand All @@ -35,6 +35,7 @@ func compileAndStartTestServer() {
if err != nil {
log.Println("test server error:", err)
}
compileDone <- struct{}{}
err = cmd.Wait()
if err != nil {
log.Println("test server error:", err)
Expand All @@ -43,7 +44,8 @@ func compileAndStartTestServer() {
}

func runAB() (err error) {
cmd := exec.Command("ab", []string{"-c 100", "-n 10000", "http://localhost:4242/foo"}...)
time.Sleep(time.Second * 1)
cmd := exec.Command("ab", []string{"-c 1000", "-n 100000", "http://localhost:4242/foo"}...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

Expand Down Expand Up @@ -71,6 +73,7 @@ func stopTestServer() (err error) {
log.Println("kill error:", err)
return
}

err = cmd.Wait()
if err != nil {
log.Println("kill error:", err)
Expand All @@ -82,6 +85,7 @@ func keepRestartingServer() {
time.Sleep(time.Second * 1)
for keepRestarting {
time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
// time.Sleep(time.Second * 60)
log.Println("sending kill -1")
cmd := exec.Command("./test/restart_server.sh", []string{}...)
cmd.Stdout = os.Stdout
Expand All @@ -108,17 +112,19 @@ func main() {
}

wg := sync.WaitGroup{}
var compileDone = make(chan struct{}, 1)
wg.Add(2)
go func() {
log.Println("compile and start test server")
compileAndStartTestServer()
compileAndStartTestServer(compileDone)
log.Println("test server stopped")
wg.Done()
}()

time.Sleep(time.Second * 1)

go func() {
<-compileDone
log.Println("Starting ab")
keepRestarting = true
go keepRestartingServer()
Expand Down

0 comments on commit d13ee2c

Please sign in to comment.