@@ -51,6 +51,17 @@ func (t *tester) runTests(passThruFlags []string) error {
51
51
}
52
52
log .Printf ("Not all tests passed: %v" , err )
53
53
54
+ timedOutPackages , err := t .findTimedoutTests (context .Background ())
55
+ if err != nil {
56
+ return err
57
+ }
58
+ if len (timedOutPackages ) > 0 {
59
+ // Fail immediately if we find any timeouts. We'd have to run all tests
60
+ // in the package, and this could take a long time.
61
+ log .Printf ("Found %d timed out packages. Failing" , len (timedOutPackages ))
62
+ return errors .New ("one or more tests timed out" )
63
+ }
64
+
54
65
failedTests , err := t .findFailedTests (context .Background ())
55
66
if err != nil {
56
67
return err
@@ -129,6 +140,11 @@ type failedTest struct {
129
140
Test string
130
141
}
131
142
143
+ type timedOutPackage struct {
144
+ Package string
145
+ Outputs string
146
+ }
147
+
132
148
func (t * tester ) findFailedTests (ctx context.Context ) ([]failedTest , error ) {
133
149
db , err := sql .Open ("sqlite" , t .Dir + dbPath )
134
150
if err != nil {
@@ -151,6 +167,49 @@ func (t *tester) findFailedTests(ctx context.Context) ([]failedTest, error) {
151
167
return out , nil
152
168
}
153
169
170
+ func (t * tester ) findTimedoutTests (ctx context.Context ) ([]timedOutPackage , error ) {
171
+ db , err := sql .Open ("sqlite" , t .Dir + dbPath )
172
+ if err != nil {
173
+ return nil , err
174
+ }
175
+ defer db .Close ()
176
+
177
+ rows , err := db .QueryContext (ctx , `WITH failed_packages AS (
178
+ SELECT
179
+ Package
180
+ FROM
181
+ test_results
182
+ WHERE
183
+ Action = 'fail'
184
+ AND Elapsed > 300
185
+ )
186
+ SELECT
187
+ test_results.Package, GROUP_CONCAT(Output, "") as Outputs
188
+ FROM
189
+ test_results
190
+ INNER JOIN
191
+ failed_packages
192
+ ON
193
+ test_results.Package = failed_packages.Package
194
+ GROUP BY
195
+ test_results.Package
196
+ HAVING
197
+ Outputs LIKE '%timed out%'
198
+ ORDER BY Time;` )
199
+ if err != nil {
200
+ return nil , err
201
+ }
202
+ var out []timedOutPackage
203
+ for rows .Next () {
204
+ var pkg , outputs string
205
+ if err := rows .Scan (& pkg , & outputs ); err != nil {
206
+ return nil , err
207
+ }
208
+ out = append (out , timedOutPackage {pkg , outputs })
209
+ }
210
+ return out , nil
211
+ }
212
+
154
213
func filterOutFlags (flags []string , exclude * regexp.Regexp ) []string {
155
214
out := make ([]string , 0 , len (flags ))
156
215
for _ , f := range flags {
@@ -170,20 +229,45 @@ func (t *tester) summarize() (string, error) {
170
229
if err != nil {
171
230
return "" , err
172
231
}
232
+ timeouts , err := t .findTimedoutTests (ctx )
233
+ if err != nil {
234
+ return "" , err
235
+ }
236
+
237
+ testFailureCount := len (testFailures ) + len (timeouts )
173
238
174
239
plural := "s"
175
- if len ( testFailures ) == 1 {
240
+ if testFailureCount == 1 {
176
241
plural = ""
177
242
}
178
- out .WriteString (fmt .Sprintf ("## %d Test Failure%s\n \n " , len ( testFailures ) , plural ))
243
+ out .WriteString (fmt .Sprintf ("## %d Test Failure%s\n \n " , testFailureCount , plural ))
179
244
180
- db , err := sql .Open ("sqlite" , t .Dir + dbPath )
181
- if err != nil {
182
- return "" , err
245
+ if len (timeouts ) > 0 {
246
+ out .WriteString ("### Timed Out Tests\n \n " )
247
+ for _ , timeout := range timeouts {
248
+ _ , err = out .WriteString (fmt .Sprintf (`<details>
249
+ <summary>%s</summary>
250
+ <pre>
251
+ %s
252
+ </pre>
253
+ </details>` , timeout .Package , timeout .Outputs ))
254
+ if err != nil {
255
+ return "" , err
256
+ }
257
+ }
258
+ out .WriteString ("\n " )
183
259
}
184
- defer db .Close ()
185
260
186
- rows , err := db .QueryContext (ctx , `SELECT
261
+ if len (testFailures ) > 0 {
262
+ out .WriteString ("### Failed Tests\n \n " )
263
+
264
+ db , err := sql .Open ("sqlite" , t .Dir + dbPath )
265
+ if err != nil {
266
+ return "" , err
267
+ }
268
+ defer db .Close ()
269
+
270
+ rows , err := db .QueryContext (ctx , `SELECT
187
271
tr_output.Package,
188
272
tr_output.Test,
189
273
GROUP_CONCAT(tr_output.Output, "") AS Outputs
@@ -204,22 +288,23 @@ GROUP BY
204
288
tr_output.Test
205
289
ORDER BY
206
290
MIN(tr_output.Time);` )
207
- if err != nil {
208
- return "" , err
209
- }
210
- for rows .Next () {
211
- var pkg , test , outputs string
212
- if err := rows .Scan (& pkg , & test , & outputs ); err != nil {
291
+ if err != nil {
213
292
return "" , err
214
293
}
215
- _ , err = out .WriteString (fmt .Sprintf (`<details>
294
+ for rows .Next () {
295
+ var pkg , test , outputs string
296
+ if err := rows .Scan (& pkg , & test , & outputs ); err != nil {
297
+ return "" , err
298
+ }
299
+ _ , err = out .WriteString (fmt .Sprintf (`<details>
216
300
<summary>%s.%s</summary>
217
301
<pre>
218
302
%s
219
303
</pre>
220
304
</details>` , pkg , test , outputs ))
221
- if err != nil {
222
- return "" , err
305
+ if err != nil {
306
+ return "" , err
307
+ }
223
308
}
224
309
}
225
310
return out .String (), nil
0 commit comments