File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ func (a *App) Run() error {
102102 server := srv
103103 eg .Go (func () error {
104104 <- ctx .Done () // wait for stop signal
105- stopCtx := octx
105+ stopCtx := context . WithoutCancel ( octx )
106106 if a .opts .stopTimeout > 0 {
107107 var cancel context.CancelFunc
108108 stopCtx , cancel = context .WithTimeout (stopCtx , a .opts .stopTimeout )
Original file line number Diff line number Diff line change @@ -283,3 +283,18 @@ func TestApp_Context(t *testing.T) {
283283 })
284284 }
285285}
286+
287+ func TestApp_ContextCanceled (t * testing.T ) {
288+ ctx , stop := context .WithCancel (context .Background ())
289+ stopFn := func (ctx context.Context ) error {
290+ select {
291+ case <- ctx .Done ():
292+ t .Fatal ("context should not be done yet" )
293+ default :
294+ }
295+ return nil
296+ }
297+ app := New (Context (ctx ), Server (& mockServer {stopFn : stopFn }), StopTimeout (time .Hour ))
298+ time .AfterFunc (time .Millisecond * 10 , stop )
299+ _ = app .Run ()
300+ }
Original file line number Diff line number Diff line change @@ -86,10 +86,17 @@ func TestLogger(t *testing.T) {
8686 }
8787}
8888
89- type mockServer struct {}
89+ type mockServer struct {
90+ stopFn func (context.Context ) error
91+ }
9092
9193func (m * mockServer ) Start (_ context.Context ) error { return nil }
92- func (m * mockServer ) Stop (_ context.Context ) error { return nil }
94+ func (m * mockServer ) Stop (ctx context.Context ) error {
95+ if m .stopFn != nil {
96+ return m .stopFn (ctx )
97+ }
98+ return nil
99+ }
93100
94101func TestServer (t * testing.T ) {
95102 o := & options {}
You can’t perform that action at this time.
0 commit comments