61
61
62
62
class ProgressIndicator (object ):
63
63
64
- def __init__ (self , cases ):
64
+ def __init__ (self , cases , flaky_tests_mode ):
65
65
self .cases = cases
66
+ self .flaky_tests_mode = flaky_tests_mode
66
67
self .parallel_queue = Queue (len (cases ))
67
68
self .sequential_queue = Queue (len (cases ))
68
69
for case in cases :
@@ -251,7 +252,10 @@ def HasRun(self, output):
251
252
self ._done += 1
252
253
command = basename (output .command [- 1 ])
253
254
if output .UnexpectedOutput ():
254
- logger .info ('not ok %i - %s' % (self ._done , command ))
255
+ status_line = 'not ok %i - %s' % (self ._done , command )
256
+ if FLAKY in output .test .outcomes and self .flaky_tests_mode == DONTCARE :
257
+ status_line = status_line + ' # TODO : Fix flaky test'
258
+ logger .info (status_line )
255
259
for l in output .output .stderr .splitlines ():
256
260
logger .info ('#' + l )
257
261
for l in output .output .stdout .splitlines ():
@@ -262,7 +266,10 @@ def HasRun(self, output):
262
266
logger .info (
263
267
'ok %i - %s # skip %s' % (self ._done , command , skip .group (1 )))
264
268
else :
265
- logger .info ('ok %i - %s' % (self ._done , command ))
269
+ status_line = 'ok %i - %s' % (self ._done , command )
270
+ if FLAKY in output .test .outcomes :
271
+ status_line = status_line + ' # TODO : Fix flaky test'
272
+ logger .info (status_line )
266
273
267
274
duration = output .test .duration
268
275
@@ -280,8 +287,8 @@ def Done(self):
280
287
281
288
class CompactProgressIndicator (ProgressIndicator ):
282
289
283
- def __init__ (self , cases , templates ):
284
- super (CompactProgressIndicator , self ).__init__ (cases )
290
+ def __init__ (self , cases , flaky_tests_mode , templates ):
291
+ super (CompactProgressIndicator , self ).__init__ (cases , flaky_tests_mode )
285
292
self .templates = templates
286
293
self .last_status_length = 0
287
294
self .start_time = time .time ()
@@ -336,29 +343,29 @@ def PrintProgress(self, name):
336
343
337
344
class ColorProgressIndicator (CompactProgressIndicator ):
338
345
339
- def __init__ (self , cases ):
346
+ def __init__ (self , cases , flaky_tests_mode ):
340
347
templates = {
341
348
'status_line' : "[%(mins)02i:%(secs)02i|\033 [34m%%%(remaining) 4d\033 [0m|\033 [32m+%(passed) 4d\033 [0m|\033 [31m-%(failed) 4d\033 [0m]: %(test)s" ,
342
349
'stdout' : "\033 [1m%s\033 [0m" ,
343
350
'stderr' : "\033 [31m%s\033 [0m" ,
344
351
}
345
- super (ColorProgressIndicator , self ).__init__ (cases , templates )
352
+ super (ColorProgressIndicator , self ).__init__ (cases , flaky_tests_mode , templates )
346
353
347
354
def ClearLine (self , last_line_length ):
348
355
print "\033 [1K\r " ,
349
356
350
357
351
358
class MonochromeProgressIndicator (CompactProgressIndicator ):
352
359
353
- def __init__ (self , cases ):
360
+ def __init__ (self , cases , flaky_tests_mode ):
354
361
templates = {
355
362
'status_line' : "[%(mins)02i:%(secs)02i|%%%(remaining) 4d|+%(passed) 4d|-%(failed) 4d]: %(test)s" ,
356
363
'stdout' : '%s' ,
357
364
'stderr' : '%s' ,
358
365
'clear' : lambda last_line_length : ("\r " + (" " * last_line_length ) + "\r " ),
359
366
'max_length' : 78
360
367
}
361
- super (MonochromeProgressIndicator , self ).__init__ (cases , templates )
368
+ super (MonochromeProgressIndicator , self ).__init__ (cases , flaky_tests_mode , templates )
362
369
363
370
def ClearLine (self , last_line_length ):
364
371
print ("\r " + (" " * last_line_length ) + "\r " ),
@@ -780,8 +787,8 @@ def GetVmFlags(self, testcase, mode):
780
787
def GetTimeout (self , mode ):
781
788
return self .timeout * TIMEOUT_SCALEFACTOR [ARCH_GUESS or 'ia32' ][mode ]
782
789
783
- def RunTestCases (cases_to_run , progress , tasks ):
784
- progress = PROGRESS_INDICATORS [progress ](cases_to_run )
790
+ def RunTestCases (cases_to_run , progress , tasks , flaky_tests_mode ):
791
+ progress = PROGRESS_INDICATORS [progress ](cases_to_run , flaky_tests_mode )
785
792
return progress .Run (tasks )
786
793
787
794
@@ -805,7 +812,8 @@ def BuildRequirements(context, requirements, mode, scons_flags):
805
812
TIMEOUT = 'timeout'
806
813
CRASH = 'crash'
807
814
SLOW = 'slow'
808
-
815
+ FLAKY = 'flaky'
816
+ DONTCARE = 'dontcare'
809
817
810
818
class Expression (object ):
811
819
pass
@@ -1253,6 +1261,9 @@ def BuildOptions():
1253
1261
default = False , action = "store_true" )
1254
1262
result .add_option ("--cat" , help = "Print the source of the tests" ,
1255
1263
default = False , action = "store_true" )
1264
+ result .add_option ("--flaky-tests" ,
1265
+ help = "Regard tests marked as flaky (run|skip|dontcare)" ,
1266
+ default = "run" )
1256
1267
result .add_option ("--warn-unused" , help = "Report unused rules" ,
1257
1268
default = False , action = "store_true" )
1258
1269
result .add_option ("-j" , help = "The number of parallel tasks to run" ,
@@ -1303,6 +1314,9 @@ def ProcessOptions(options):
1303
1314
return False
1304
1315
if options .J :
1305
1316
options .j = multiprocessing .cpu_count ()
1317
+ if options .flaky_tests not in ["run" , "skip" , "dontcare" ]:
1318
+ print "Unknown flaky-tests mode %s" % options .flaky_tests
1319
+ return False
1306
1320
return True
1307
1321
1308
1322
@@ -1505,7 +1519,9 @@ def Main():
1505
1519
1506
1520
result = None
1507
1521
def DoSkip (case ):
1508
- return SKIP in case .outcomes or SLOW in case .outcomes
1522
+ if SKIP in case .outcomes or SLOW in case .outcomes :
1523
+ return True
1524
+ return FLAKY in case .outcomes and options .flaky_tests == SKIP
1509
1525
cases_to_run = [ c for c in all_cases if not DoSkip (c ) ]
1510
1526
if options .run is not None :
1511
1527
# Must ensure the list of tests is sorted before selecting, to avoid
@@ -1522,7 +1538,7 @@ def DoSkip(case):
1522
1538
else :
1523
1539
try :
1524
1540
start = time .time ()
1525
- if RunTestCases (cases_to_run , options .progress , options .j ):
1541
+ if RunTestCases (cases_to_run , options .progress , options .j , options . flaky_tests ):
1526
1542
result = 0
1527
1543
else :
1528
1544
result = 1
0 commit comments