Skip to content

Commit a0b7cd4

Browse files
craig[bot]andreimatei
craig[bot]
andcommitted
Merge #31405
31405: roachtest: fix stdout output r=andreimatei a=andreimatei roachtest's intention is that if there's no parallelism is requested, logs are teed to stdout/stderr in addition to the test.log file. No parallelism is specified explicitly by passing -p 1, or implicitly by running a single test. This patch fixes a bug where the "implicit" part was no longer behaving as expected wrt the logs. The bug was introduced by a previous patch that tried to reduce the scope of the "parallelism" global, but missed the use in rootLogger(); the inferring of parallelism=1 was no longer modifying the global. This patch kills the global for good. Release note: None Co-authored-by: Andrei Matei <[email protected]>
2 parents a1c2f7d + 0261e22 commit a0b7cd4

File tree

4 files changed

+50
-26
lines changed

4 files changed

+50
-26
lines changed

pkg/cmd/roachtest/cluster.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ type clusterConfig struct {
627627
nodes []nodeSpec
628628
artifactsDir string
629629
localCluster bool
630+
teeOpt teeOptType
630631
}
631632

632633
// newCluster creates a new roachprod cluster.
@@ -668,7 +669,7 @@ func newCluster(ctx context.Context, cfg clusterConfig) (*cluster, error) {
668669
}
669670

670671
logPath := filepath.Join(cfg.artifactsDir, "test.log")
671-
l, err := rootLogger(logPath)
672+
l, err := rootLogger(logPath, cfg.teeOpt)
672673
if err != nil {
673674
return nil, err
674675
}
@@ -700,6 +701,9 @@ func newCluster(ctx context.Context, cfg clusterConfig) (*cluster, error) {
700701
}
701702

702703
type attachOpt struct {
704+
// If set, the c.l will output to stdout/stderr.
705+
teeToStdout bool
706+
703707
skipValidation bool
704708
// Implies skipWipe.
705709
skipStop bool
@@ -719,7 +723,11 @@ func attachToExistingCluster(
719723
}
720724

721725
logPath := filepath.Join(artifactsDir, "test.log")
722-
l, err := rootLogger(logPath)
726+
teeOpt := noTee
727+
if opt.teeToStdout {
728+
teeOpt = teeToStdout
729+
}
730+
l, err := rootLogger(logPath, teeOpt)
723731
if err != nil {
724732
return nil, err
725733
}
@@ -819,9 +827,9 @@ func (c *cluster) validate(ctx context.Context, nodes []nodeSpec, l *logger) err
819827

820828
// clone creates a new cluster object that refers to the same cluster as the
821829
// receiver, but is associated with the specified test.
822-
func (c *cluster) clone(t *test) *cluster {
830+
func (c *cluster) clone(t *test, teeOpt teeOptType) *cluster {
823831
logPath := filepath.Join(t.ArtifactsDir(), "test.log")
824-
l, err := rootLogger(logPath)
832+
l, err := rootLogger(logPath, teeOpt)
825833
if err != nil {
826834
t.Fatal(err)
827835
}

pkg/cmd/roachtest/log.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,16 @@ func (cfg *loggerConfig) newLogger(path string) (*logger, error) {
106106
}, nil
107107
}
108108

109-
func rootLogger(path string) (*logger, error) {
109+
type teeOptType bool
110+
111+
const (
112+
teeToStdout teeOptType = true
113+
noTee teeOptType = false
114+
)
115+
116+
func rootLogger(path string, teeOpt teeOptType) (*logger, error) {
110117
var stdout, stderr io.Writer
111-
// Log to stdout/stderr if we're not running tests in parallel.
112-
if parallelism == 1 {
118+
if teeOpt == teeToStdout {
113119
stdout = os.Stdout
114120
stderr = os.Stderr
115121
}

pkg/cmd/roachtest/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
)
2525

2626
func main() {
27+
parallelism := 10
28+
2729
cobra.EnableCommandSorting = false
2830

2931
var rootCmd = &cobra.Command{

pkg/cmd/roachtest/test.go

+27-19
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
)
4141

4242
var (
43-
parallelism = 10
4443
count = 1
4544
debugEnabled = false
4645
postIssues = true
@@ -346,8 +345,14 @@ func (r *registry) Run(filter []string, parallelism int) int {
346345
if count == 1 {
347346
runNum = 0
348347
}
348+
// Log to stdout/stderr if we're not running tests in parallel.
349+
teeOpt := noTee
350+
if parallelism == 1 {
351+
teeOpt = teeToStdout
352+
}
349353
r.runAsync(
350-
ctx, tests[i], filterRE, nil /* parent */, nil /* cluster */, runNum, func(failed bool) {
354+
ctx, tests[i], filterRE, nil /* parent */, nil, /* cluster */
355+
runNum, teeOpt, func(failed bool) {
351356
wg.Done()
352357
<-sem
353358
})
@@ -709,6 +714,7 @@ func (r *registry) runAsync(
709714
parent *test,
710715
c *cluster,
711716
runNum int,
717+
teeOpt teeOptType,
712718
done func(failed bool),
713719
) {
714720
artifactsSuffix := ""
@@ -873,6 +879,7 @@ func (r *registry) runAsync(
873879
nodes: t.spec.Nodes,
874880
artifactsDir: t.ArtifactsDir(),
875881
localCluster: local,
882+
teeOpt: teeOpt,
876883
}
877884
var err error
878885
c, err = newCluster(ctx, cfg)
@@ -898,7 +905,7 @@ func (r *registry) runAsync(
898905
}()
899906
}
900907
} else {
901-
c = c.clone(t)
908+
c = c.clone(t, teeOpt)
902909
}
903910

904911
// If we have subtests, handle them here and return.
@@ -907,22 +914,23 @@ func (r *registry) runAsync(
907914
if t.spec.SubTests[i].matchRegex(filter) {
908915
var wg sync.WaitGroup
909916
wg.Add(1)
910-
r.runAsync(ctx, &t.spec.SubTests[i], filter, t, c, runNum, func(failed bool) {
911-
if failed {
912-
// Mark the parent test as failed since one of the subtests
913-
// failed.
914-
t.mu.Lock()
915-
t.mu.failed = true
916-
t.mu.Unlock()
917-
}
918-
if failed && debugEnabled {
919-
// The test failed and debugging is enabled. Don't try to stumble
920-
// forward running another test or subtest, just exit
921-
// immediately.
922-
os.Exit(1)
923-
}
924-
wg.Done()
925-
})
917+
r.runAsync(ctx, &t.spec.SubTests[i], filter, t, c,
918+
runNum, teeOpt, func(failed bool) {
919+
if failed {
920+
// Mark the parent test as failed since one of the subtests
921+
// failed.
922+
t.mu.Lock()
923+
t.mu.failed = true
924+
t.mu.Unlock()
925+
}
926+
if failed && debugEnabled {
927+
// The test failed and debugging is enabled. Don't try to stumble
928+
// forward running another test or subtest, just exit
929+
// immediately.
930+
os.Exit(1)
931+
}
932+
wg.Done()
933+
})
926934
wg.Wait()
927935
}
928936
}

0 commit comments

Comments
 (0)