@@ -16,6 +16,8 @@ import (
1616 "fmt"
1717 "io"
1818 "net/http"
19+ "runtime/pprof"
20+ "strings"
1921 "testing"
2022 "time"
2123
@@ -59,35 +61,63 @@ func TestReadWriteProfilerExecutionDetails(t *testing.T) {
5961
6062 runner := sqlutils .MakeSQLRunner (sqlDB )
6163
62- jobs .RegisterConstructor (jobspb .TypeImport , func (j * jobs.Job , _ * cluster.Settings ) jobs.Resumer {
63- return fakeExecResumer {
64- OnResume : func (ctx context.Context ) error {
65- p := sql.PhysicalPlan {}
66- infra := physicalplan .NewPhysicalInfrastructure (uuid .FastMakeV4 (), base .SQLInstanceID (1 ))
67- p .PhysicalInfrastructure = infra
68- jobsprofiler .StorePlanDiagram (ctx , s .Stopper (), & p , s .InternalDB ().(isql.DB ), j .ID ())
69- checkForPlanDiagram (ctx , t , s .InternalDB ().(isql.DB ), j .ID ())
70- return nil
71- },
72- }
73- }, jobs .UsesTenantCostControl )
74-
7564 runner .Exec (t , `CREATE TABLE t (id INT)` )
7665 runner .Exec (t , `INSERT INTO t SELECT generate_series(1, 100)` )
7766
7867 t .Run ("read/write DistSQL diagram" , func (t * testing.T ) {
68+ jobs .RegisterConstructor (jobspb .TypeImport , func (j * jobs.Job , _ * cluster.Settings ) jobs.Resumer {
69+ return fakeExecResumer {
70+ OnResume : func (ctx context.Context ) error {
71+ p := sql.PhysicalPlan {}
72+ infra := physicalplan .NewPhysicalInfrastructure (uuid .FastMakeV4 (), base .SQLInstanceID (1 ))
73+ p .PhysicalInfrastructure = infra
74+ jobsprofiler .StorePlanDiagram (ctx , s .Stopper (), & p , s .InternalDB ().(isql.DB ), j .ID ())
75+ checkForPlanDiagram (ctx , t , s .InternalDB ().(isql.DB ), j .ID ())
76+ return nil
77+ },
78+ }
79+ }, jobs .UsesTenantCostControl )
80+
7981 var importJobID int
8082 runner .QueryRow (t , `IMPORT INTO t CSV DATA ('nodelocal://1/foo') WITH DETACHED` ).Scan (& importJobID )
8183 jobutils .WaitForJobToSucceed (t , runner , jobspb .JobID (importJobID ))
8284
8385 runner .Exec (t , `SELECT crdb_internal.request_job_execution_details($1)` , importJobID )
84- checkExecutionDetails (t , s , jobspb .JobID (importJobID ), "distsql" )
86+ distSQLDiagram := checkExecutionDetails (t , s , jobspb .JobID (importJobID ), "distsql" )
87+ require .Regexp (t , "<meta http-equiv=\" Refresh\" content=\" 0\\ ; url=https://cockroachdb\\ .github\\ .io/distsqlplan/decode.html.*>" , string (distSQLDiagram ))
88+ })
89+
90+ t .Run ("read/write goroutines" , func (t * testing.T ) {
91+ blockCh := make (chan struct {})
92+ continueCh := make (chan struct {})
93+ defer close (blockCh )
94+ defer close (continueCh )
95+ jobs .RegisterConstructor (jobspb .TypeImport , func (j * jobs.Job , _ * cluster.Settings ) jobs.Resumer {
96+ return fakeExecResumer {
97+ OnResume : func (ctx context.Context ) error {
98+ pprof .Do (ctx , pprof .Labels ("foo" , "bar" ), func (ctx2 context.Context ) {
99+ blockCh <- struct {}{}
100+ <- continueCh
101+ })
102+ return nil
103+ },
104+ }
105+ }, jobs .UsesTenantCostControl )
106+ var importJobID int
107+ runner .QueryRow (t , `IMPORT INTO t CSV DATA ('nodelocal://1/foo') WITH DETACHED` ).Scan (& importJobID )
108+ <- blockCh
109+ runner .Exec (t , `SELECT crdb_internal.request_job_execution_details($1)` , importJobID )
110+ goroutines := checkExecutionDetails (t , s , jobspb .JobID (importJobID ), "goroutines" )
111+ continueCh <- struct {}{}
112+ jobutils .WaitForJobToSucceed (t , runner , jobspb .JobID (importJobID ))
113+ require .True (t , strings .Contains (string (goroutines ), fmt .Sprintf ("labels: {\" foo\" :\" bar\" , \" job\" :\" IMPORT id=%d\" , \" n\" :\" 1\" }" , importJobID )))
114+ require .True (t , strings .Contains (string (goroutines ), "github.com/cockroachdb/cockroach/pkg/sql_test.fakeExecResumer.Resume" ))
85115 })
86116}
87117
88118func checkExecutionDetails (
89119 t * testing.T , s serverutils.TestServerInterface , jobID jobspb.JobID , filename string ,
90- ) {
120+ ) [] byte {
91121 t .Helper ()
92122
93123 client , err := s .GetAdminHTTPClient ()
@@ -112,4 +142,5 @@ func checkExecutionDetails(
112142 data , err := io .ReadAll (r )
113143 require .NoError (t , err )
114144 require .NotEmpty (t , data )
145+ return data
115146}
0 commit comments