make sure the test shuts down the server gracefully.

pull/17/head
John Shahid 2013-10-31 12:35:41 -04:00
parent c77802536a
commit 2a5c32710d
2 changed files with 9 additions and 11 deletions

View File

@ -12,6 +12,7 @@ import (
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
"syscall"
"testing" "testing"
"time" "time"
) )
@ -111,7 +112,7 @@ func (self *Server) stop() {
return return
} }
self.p.Kill() self.p.Signal(syscall.SIGTERM)
self.p.Wait() self.p.Wait()
} }

View File

@ -23,15 +23,15 @@ const (
gitSha = "" gitSha = ""
) )
func waitForSignals(shouldStop chan<- bool, stopped <-chan bool) { func waitForSignals(stopped <-chan bool) {
ch := make(chan os.Signal) ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP, syscall.SIGUSR1, syscall.SIGUSR2) signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT)
for { for {
sig := <-ch sig := <-ch
fmt.Printf("Received signal: %s", sig.String()) fmt.Printf("Received signal: %s\n", sig.String())
switch sig { switch sig {
case syscall.SIGINT, syscall.SIGTERM: case syscall.SIGINT, syscall.SIGTERM:
shouldStop <- true runtime.SetCPUProfileRate(0)
<-stopped <-stopped
os.Exit(0) os.Exit(0)
} }
@ -48,21 +48,18 @@ func startProfiler(filename *string) error {
return err return err
} }
runtime.SetCPUProfileRate(500) runtime.SetCPUProfileRate(500)
shouldStop := make(chan bool)
stopped := make(chan bool) stopped := make(chan bool)
go waitForSignals(shouldStop, stopped) go waitForSignals(stopped)
go func() { go func() {
for { for {
select { select {
case <-shouldStop:
cpuProfileFile.Close()
stopped <- true
break
default: default:
data := runtime.CPUProfile() data := runtime.CPUProfile()
if data == nil { if data == nil {
cpuProfileFile.Close()
stopped <- true
break break
} }
cpuProfileFile.Write(data) cpuProfileFile.Write(data)