refactor(api): make shutdown timeout configurable for tests (#9980)
This is extracted from PR #9175, which adds some tests that seem to need a longer shutdown timeout when running on GitHub Actions.
This commit is contained in:
+3
-1
@@ -92,6 +92,7 @@ type service struct {
|
||||
listenerAddr net.Addr
|
||||
exitChan chan *svcutil.FatalErr
|
||||
miscDB *db.NamespacedKV
|
||||
shutdownTimeout time.Duration
|
||||
|
||||
guiErrors logger.Recorder
|
||||
systemLog logger.Recorder
|
||||
@@ -129,6 +130,7 @@ func New(id protocol.DeviceID, cfg config.Wrapper, assetDir, tlsDefaultCommonNam
|
||||
startedOnce: make(chan struct{}),
|
||||
exitChan: make(chan *svcutil.FatalErr, 1),
|
||||
miscDB: miscDB,
|
||||
shutdownTimeout: 100 * time.Millisecond,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,7 +453,7 @@ func (s *service) Serve(ctx context.Context) error {
|
||||
}
|
||||
// Give it a moment to shut down gracefully, e.g. if we are restarting
|
||||
// due to a config change through the API, let that finish successfully.
|
||||
timeout, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||
timeout, cancel := context.WithTimeout(context.Background(), s.shutdownTimeout)
|
||||
defer cancel()
|
||||
if err := srv.Shutdown(timeout); err == timeout.Err() {
|
||||
srv.Close()
|
||||
|
||||
Reference in New Issue
Block a user