fix g.Wait not support OS Signal #2752 (#2768)

This commit is contained in:
xyqweb
2023-07-19 20:06:06 +08:00
committed by GitHub
parent 41c0dde9bf
commit d72997da04
2 changed files with 16 additions and 0 deletions

View File

@ -447,6 +447,9 @@ func (s *Server) Run() {
func Wait() {
var ctx = context.TODO()
// Signal handler in asynchronous way.
go handleProcessSignal()
<-allShutdownChan
// Remove plugins.
serverMapping.Iterator(func(k string, v interface{}) bool {

View File

@ -168,3 +168,16 @@ func Test_BuildParams(t *testing.T) {
}
})
}
func Test_ServerSignal(t *testing.T) {
s := g.Server(guid.S())
s.BindHandler("/", func(r *ghttp.Request) {
r.Response.Write("hello world")
})
gtest.Assert(s.Start(), nil)
g.Wait()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
t.AssertEQ(s.Shutdown(), nil)
})
}