Skip to content

Commit

Permalink
fix g.Wait not support OS Signal #2752 (#2768)
Browse files Browse the repository at this point in the history
  • Loading branch information
xyqweb committed Jul 19, 2023
1 parent 41c0dde commit d72997d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions net/ghttp/ghttp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions net/ghttp/ghttp_z_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

0 comments on commit d72997d

Please sign in to comment.