@@ -7,6 +7,7 @@ package stop_test
7
7
8
8
import (
9
9
"context"
10
+ "fmt"
10
11
"runtime"
11
12
"sync"
12
13
"sync/atomic"
@@ -21,7 +22,9 @@ import (
21
22
"github.com/cockroachdb/cockroach/pkg/util/stop"
22
23
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
23
24
"github.com/cockroachdb/cockroach/pkg/util/tracing"
25
+ "github.com/cockroachdb/cockroach/pkg/util/tracing/tracingpb"
24
26
"github.com/cockroachdb/errors"
27
+ "github.com/petermattis/goid"
25
28
"github.com/stretchr/testify/require"
26
29
)
27
30
@@ -742,3 +745,33 @@ func TestHandleWithoutActivateOrRelease(t *testing.T) {
742
745
}
743
746
})
744
747
}
748
+
749
+ func TestHandleSetsGoroutineOnSpan (t * testing.T ) {
750
+ defer leaktest .AfterTest (t )()
751
+ ctx := context .Background ()
752
+
753
+ s := stop .NewStopper ()
754
+ defer s .Stop (ctx )
755
+
756
+ tracer := tracing .NewTracer ()
757
+ sp := tracer .StartSpan ("test span" )
758
+ sp .SetRecordingType (tracingpb .RecordingVerbose )
759
+ ctx = tracing .ContextWithSpan (ctx , sp )
760
+
761
+ ctx , hdl , err := s .GetHandle (ctx , stop.TaskOpts {
762
+ SpanOpt : stop .ChildSpan ,
763
+ TaskName : "async task" ,
764
+ })
765
+ require .NoError (t , err )
766
+
767
+ endCh := make (chan struct {})
768
+ var goroutineID int64
769
+ go func () {
770
+ defer hdl .Activate (ctx ).Release (ctx )
771
+ goroutineID = goid .Get ()
772
+ close (endCh )
773
+ }()
774
+ <- endCh
775
+ rec := sp .FinishAndGetRecording (tracingpb .RecordingVerbose )
776
+ require .Contains (t , rec .String (), fmt .Sprintf ("gid:%d" , goroutineID ))
777
+ }
0 commit comments