You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

groutinelabel_test.go 930B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package log
  4. import (
  5. "context"
  6. "runtime/pprof"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func Test_getGoroutineLabels(t *testing.T) {
  11. pprof.Do(context.Background(), pprof.Labels(), func(ctx context.Context) {
  12. currentLabels := getGoroutineLabels()
  13. pprof.ForLabels(ctx, func(key, value string) bool {
  14. assert.EqualValues(t, value, currentLabels[key])
  15. return true
  16. })
  17. pprof.Do(ctx, pprof.Labels("Test_getGoroutineLabels", "Test_getGoroutineLabels_child1"), func(ctx context.Context) {
  18. currentLabels := getGoroutineLabels()
  19. pprof.ForLabels(ctx, func(key, value string) bool {
  20. assert.EqualValues(t, value, currentLabels[key])
  21. return true
  22. })
  23. if assert.NotNil(t, currentLabels) {
  24. assert.EqualValues(t, "Test_getGoroutineLabels_child1", currentLabels["Test_getGoroutineLabels"])
  25. }
  26. })
  27. })
  28. }