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