From 89bf9765cc12c5216f25adf06a95a5920ce0c91d Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Wed, 12 Dec 2018 10:53:10 -0700 Subject: [PATCH] fix(cmd/influxd): Refactor test cancellation out of main path. This commit moves the `Main.cancel()` execution to the `main_test.go` file so it's only executed for tests. This was interfering with the shutdown process on the regular `influxd` binary. --- cmd/influxd/main.go | 4 +++- cmd/influxd/main_test.go | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/influxd/main.go b/cmd/influxd/main.go index 4dbf32430b..6996ab0655 100644 --- a/cmd/influxd/main.go +++ b/cmd/influxd/main.go @@ -115,7 +115,6 @@ func (m *Main) URL() string { // Shutdown shuts down the HTTP server and waits for all services to clean up. func (m *Main) Shutdown(ctx context.Context) { - m.cancel() m.httpServer.Shutdown(ctx) m.logger.Info("Stopping", zap.String("service", "task")) @@ -144,6 +143,9 @@ func (m *Main) Shutdown(ctx context.Context) { m.logger.Sync() } +// Cancel executes the context cancel on the program. Used for testing. +func (m *Main) Cancel() { m.cancel() } + // Run executes the program with the given CLI arguments. func (m *Main) Run(ctx context.Context, args ...string) error { dir, err := fs.InfluxDir() diff --git a/cmd/influxd/main_test.go b/cmd/influxd/main_test.go index 8c2dac9c2b..bb69049041 100644 --- a/cmd/influxd/main_test.go +++ b/cmd/influxd/main_test.go @@ -137,6 +137,7 @@ func (m *Main) Run(ctx context.Context, args ...string) error { // Shutdown stops the program and cleans up temporary paths. func (m *Main) Shutdown(ctx context.Context) error { + m.Cancel() m.Main.Shutdown(ctx) return os.RemoveAll(m.Path) }