make sure the test shuts down the server gracefully.
parent
c77802536a
commit
2a5c32710d
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue