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

Function TestDebugCollectProfile

coderd/debug_test.go:414–606  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

412}
413
414func TestDebugCollectProfile(t *testing.T) {
415 t.Parallel()
416
417 t.Run("Defaults", func(t *testing.T) {
418 t.Parallel()
419
420 ctx := testutil.Context(t, testutil.WaitLong)
421
422 client, closer, api := newTestAPI(t)
423 defer closer.Close()
424 _ = coderdtest.CreateFirstUser(t, client)
425
426 asserter := coderdtest.AssertRBAC(t, api, client)
427
428 body, err := client.DebugCollectProfile(ctx, codersdk.DebugProfileOptions{
429 // Use a very short duration so the test finishes quickly.
430 // The noop collector means no real profiling occurs.
431 Duration: 100 * time.Millisecond,
432 })
433 require.NoError(t, err)
434 defer body.Close()
435
436 data, err := io.ReadAll(body)
437 require.NoError(t, err)
438 require.NotEmpty(t, data, "archive should not be empty")
439
440 // Verify that the response is a valid tar.gz archive containing
441 // the expected profile files.
442 files := extractTarGzFiles(t, data)
443 require.Contains(t, files, "cpu.prof")
444 require.Contains(t, files, "heap.prof")
445 require.Contains(t, files, "allocs.prof")
446 require.Contains(t, files, "block.prof")
447 require.Contains(t, files, "mutex.prof")
448 require.Contains(t, files, "goroutine.prof")
449
450 // Verify the endpoint checks the correct RBAC permission.
451 asserter.AssertChecked(t, policy.ActionRead, rbac.ResourceDebugInfo)
452 })
453
454 t.Run("CustomProfiles", func(t *testing.T) {
455 t.Parallel()
456
457 ctx := testutil.Context(t, testutil.WaitLong)
458
459 client, closer, _ := newTestAPI(t)
460 defer closer.Close()
461 _ = coderdtest.CreateFirstUser(t, client)
462
463 body, err := client.DebugCollectProfile(ctx, codersdk.DebugProfileOptions{
464 Duration: 100 * time.Millisecond,
465 Profiles: []string{"heap", "goroutine"},
466 })
467 require.NoError(t, err)
468 defer body.Close()
469
470 data, err := io.ReadAll(body)
471 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
CreateFirstUserFunction · 0.92
AssertRBACFunction · 0.92
NewFunction · 0.92
CreateAnotherUserFunction · 0.92
NewWithAPIFunction · 0.92
TryReceiveFunction · 0.92
extractTarGzFilesFunction · 0.85
DebugCollectProfileMethod · 0.80
NotEmptyMethod · 0.80
AssertCheckedMethod · 0.80
newTestAPIFunction · 0.70

Tested by

no test coverage detected