MCPcopy Index your code
hub / github.com/coder/coder / TestServer_GracefulShutdown

Function TestServer_GracefulShutdown

cli/server_test.go:2284–2322  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2282}
2283
2284func 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
2324func BenchmarkServerHelp(b *testing.B) {
2325 // server --help is a good proxy for measuring the

Callers

nothing calls this directly

Calls 10

NewFunction · 0.92
NewFunction · 0.92
SkipNowMethod · 0.80
WithContextMethod · 0.80
dbArgFunction · 0.70
waitAccessURLFunction · 0.70
TempDirMethod · 0.65
AttachMethod · 0.65
RunMethod · 0.65
ExpectMatchMethod · 0.45

Tested by

no test coverage detected