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 1002B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package log
  5. import (
  6. "context"
  7. "runtime/pprof"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func Test_getGoroutineLabels(t *testing.T) {
  12. pprof.Do(context.Background(), pprof.Labels(), func(ctx context.Context) {
  13. currentLabels := getGoroutineLabels()
  14. pprof.ForLabels(ctx, func(key, value string) bool {
  15. assert.EqualValues(t, value, currentLabels[key])
  16. return true
  17. })
  18. pprof.Do(ctx, pprof.Labels("Test_getGoroutineLabels", "Test_getGoroutineLabels_child1"), func(ctx context.Context) {
  19. currentLabels := getGoroutineLabels()
  20. pprof.ForLabels(ctx, func(key, value string) bool {
  21. assert.EqualValues(t, value, currentLabels[key])
  22. return true
  23. })
  24. if assert.NotNil(t, currentLabels) {
  25. assert.EqualValues(t, "Test_getGoroutineLabels_child1", currentLabels["Test_getGoroutineLabels"])
  26. }
  27. })
  28. })
  29. }