Atlas › Test

TestParseTestTimeouts

Exact test identity: go.temporal.io/server/tools/testrunner/TestParseTestTimeouts

Package
go.temporal.io/server/tools/testrunner
Suite / test hierarchy
TestParseTestTimeouts
Test
TestParseTestTimeouts
Introduced at
log.go ×7 Frontier kind: Joint frontier
Covered ranges
7
Covered lines
41
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/tools/testrunner/log.go 41 covered LOC · 7 ranges

Open complete file

18
19 // parseTestTimeouts parses the stdout of a test run and returns the stacktrace and names of tests that timed out.
20 > func parseTestTimeouts(stdout string) (stacktrace string, timedoutTests []string) { log.go
21 > lines := strings.Split(strings.ReplaceAll(stdout, "\r\n", "\n"), "\n")
22 > for i := 0; i < len(lines); i++ {
23 > line := lines[i]
24 > if strings.HasPrefix(line, "FAIL") {
25 > // ignore
26 > } else if strings.HasPrefix(line, "panic: test timed out after") {
27 > // parse names of tests that timed out
28 > for {
29 > i++
30 > line = strings.TrimSpace(lines[i])
31 > if strings.HasPrefix(line, "Test") {
32 > timedoutTests = append(timedoutTests, strings.Split(line, " ")[0])
33 > }
34 > if line == "" {
35 > break
36 }
37 }
38 > } else if len(timedoutTests) > 0 { log.go
39 > // collect stracktrace
40 > stacktrace += line + "\n"
41 > }
42 }
43
44 > stacktrace = fmt.Sprintf("%d timed out test(s):\n\t%v\n\n%v", log.go
45 > len(timedoutTests), strings.Join(timedoutTests, "\n\t"), testOnlyStacktrace(stacktrace))
46 > return
47 }
48
49 // testOnlyStacktrace removes all but the test stacktraces from the full stacktrace.
50 > func testOnlyStacktrace(stacktrace string) string { log.go
51 > var res string
52 > snap, _, err := stack.ScanSnapshot(strings.NewReader(stacktrace), io.Discard, stack.DefaultOpts())
53 > if err != nil && err != io.EOF {
54 return fmt.Sprintf("failed to parse stacktrace: %v", err)
55 }
56 > if snap == nil { log.go
57 return "failed to find a stacktrace"
58 }
59 > res = "abridged stacktrace:\n" log.go
60 > for _, goroutine := range snap.Goroutines {
61 > shouldPrint := slices.ContainsFunc(goroutine.Stack.Calls, func(call stack.Call) bool {
62 > return strings.HasSuffix(call.RemoteSrcPath, "_test.go")
63 > })
64 > if shouldPrint {
65 > res += fmt.Sprintf("\tgoroutine %d [%v]:\n", goroutine.ID, goroutine.State)
66 > for _, call := range goroutine.Stack.Calls {
67 > file := call.RemoteSrcPath
68 > res += fmt.Sprintf("\t\t%s:%d\n", file, call.Line)
69 > }
70 > res += "\n"
71 }
72 }
73 > return res log.go
74 }
75