(t *testing.T)
| 2282 | } |
| 2283 | |
| 2284 | func TestServer_GracefulShutdown(t *testing.T) { |
| 2285 | t.Parallel() |
| 2286 | if runtime.GOOS == "windows" { |
| 2287 | // Sending interrupt signal isn't supported on Windows! |
| 2288 | t.SkipNow() |
| 2289 | } |
| 2290 | ctx, cancelFunc := context.WithCancel(context.Background()) |
| 2291 | defer cancelFunc() |
| 2292 | |
| 2293 | root, cfg := clitest.New(t, |
| 2294 | "server", |
| 2295 | dbArg(t), |
| 2296 | "--http-address", ":0", |
| 2297 | "--access-url", "http://example.com", |
| 2298 | "--provisioner-daemons", "1", |
| 2299 | "--cache-dir", t.TempDir(), |
| 2300 | ) |
| 2301 | var stopFunc context.CancelFunc |
| 2302 | root = root.WithTestSignalNotifyContext(t, func(parent context.Context, signals ...os.Signal) (context.Context, context.CancelFunc) { |
| 2303 | if !reflect.DeepEqual(cli.StopSignalsNoInterrupt, signals) { |
| 2304 | return context.WithCancel(ctx) |
| 2305 | } |
| 2306 | var ctx context.Context |
| 2307 | ctx, stopFunc = context.WithCancel(parent) |
| 2308 | return ctx, stopFunc |
| 2309 | }) |
| 2310 | serverErr := make(chan error, 1) |
| 2311 | pty := ptytest.New(t).Attach(root) |
| 2312 | go func() { |
| 2313 | serverErr <- root.WithContext(ctx).Run() |
| 2314 | }() |
| 2315 | _ = waitAccessURL(t, cfg) |
| 2316 | // It's fair to assume `stopFunc` isn't nil here, because the server |
| 2317 | // has started and access URL is propagated. |
| 2318 | stopFunc() |
| 2319 | pty.ExpectMatch("waiting for provisioner jobs to complete") |
| 2320 | err := <-serverErr |
| 2321 | require.NoError(t, err) |
| 2322 | } |
| 2323 | |
| 2324 | func BenchmarkServerHelp(b *testing.B) { |
| 2325 | // server --help is a good proxy for measuring the |
nothing calls this directly
no test coverage detected