1
1
from contextlib import contextmanager
2
2
from time import gmtime
3
3
from time import strftime
4
+ from time import strptime
4
5
from urlparse import urlparse
6
+ import time
5
7
import random
6
8
import os
7
9
import re
8
10
import shutil
9
- import time
10
11
import tempfile
11
12
import simplejson
12
13
import pytest
@@ -73,6 +74,10 @@ def _move_file_to_dropzone_script(dropzone_selector):
73
74
VERIFICATION_SUCCESSFUL_MESSAGE = "Verification Successful"
74
75
VERIFICATION_FAILED_MESSAGE = "Verification failed."
75
76
77
+ # Max test runtime into saucelabs
78
+ # 2.5 hours (3 hours max)
79
+ SAUCELABS_TIMEOUT_SECONDS = 10800 - 1800
80
+
76
81
# Throttle between compiles
77
82
COMPILES_PER_MINUTE = 10
78
83
def throttle_compile ():
@@ -85,6 +90,31 @@ def throttle_compile():
85
90
with open (BOARDS_PATH ) as f :
86
91
BOARDS_DB = simplejson .loads (f .read ())
87
92
93
+ def read_last_log (compile_type ):
94
+ logs = os .listdir (get_path ('logs' ))
95
+ logs_re = re .compile (r'.+cb_compile_tester.+' )
96
+ if compile_type == 'library' :
97
+ logs_re = re .compile (r'.+libraries_test.+' )
98
+ logs = sorted ([x for x in logs if x != '.gitignore' and logs_re .match (x )])
99
+
100
+ log_timestamp_re = re .compile (r'(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})-.+\.json' )
101
+ log = None
102
+ timestamp = None
103
+ if len (logs ) > 0 :
104
+ log = logs [- 1 ]
105
+ timestamp = log_timestamp_re .match (log ).group (1 )
106
+
107
+ last_log = None
108
+ if log :
109
+ with open (get_path ('logs' , log )) as f :
110
+ last_log = simplejson .loads (f .read ())
111
+
112
+ return {
113
+ 'log' : last_log ,
114
+ 'timestamp' : timestamp
115
+ }
116
+
117
+
88
118
# Creates a report json after each compile test
89
119
def report_creator (compile_type , log_entry , log_file ):
90
120
logs = os .listdir (get_path ('logs' ))
@@ -429,19 +459,39 @@ def compile_sketches(self, sketches, iframe=False, logfile=None, compile_type='s
429
459
430
460
# Log filename
431
461
log_time = gmtime ()
462
+ # Keeps the logs of each compile
463
+ log_entry = {}
464
+
465
+ urls_visited = {}
466
+ last_log = read_last_log (compile_type )
467
+ if last_log ['log' ]:
468
+ # resume previous compile
469
+ log_time = strptime (last_log ['timestamp' ], '%Y-%m-%d_%H-%M-%S' )
470
+ log_entry = last_log ['log' ]
471
+ for url in last_log ['log' ]:
472
+ urls_visited [url ] = True
473
+
474
+ urls_to_visit = []
475
+ for url in sketches :
476
+ if url not in urls_visited :
477
+ urls_to_visit .append (url )
478
+
479
+ if len (urls_to_visit ) == 0 :
480
+ urls_to_visit = sketches
481
+ log_entry = {}
482
+ log_time = gmtime ()
483
+
432
484
current_date = strftime ('%Y-%m-%d' , log_time )
433
485
# Initialize DisqusWrapper
434
486
disqus_wrapper = DisqusWrapper (log_time )
435
487
if logfile :
436
488
log_file = strftime (logfile , log_time )
437
- # Keeps the logs of each compile
438
- log_entry = {}
439
- # Compile all the input when in Full mode or a single sketch/example
440
- sketches = sketches if self .run_full_compile_tests else sketches [0 :1 ]
441
489
442
- print '\n Compiling:' , len (sketches ), 'sketches'
443
- total_sketches = len (sketches )
444
- for counter , sketch in enumerate (sketches ):
490
+ print '\n Compiling:' , len (urls_to_visit ), 'sketches'
491
+ total_sketches = len (urls_to_visit )
492
+ tic = time .time ()
493
+
494
+ for counter , sketch in enumerate (urls_to_visit ):
445
495
# Read the boards map in case current sketch/example requires a special board configuration
446
496
boards = BOARDS_DB ['default_boards' ]
447
497
url_fragments = urlparse (sketch )
@@ -497,9 +547,16 @@ def compile_sketches(self, sketches, iframe=False, logfile=None, compile_type='s
497
547
498
548
print '.' ,
499
549
550
+ toc = time .time ()
551
+ if toc - tic >= SAUCELABS_TIMEOUT_SECONDS :
552
+ print '\n Stopping tests to avoid saucelabs timeout'
553
+ print 'Test duration:' , int (toc - tic ), 'sec'
554
+ return
555
+
500
556
# Generate a report if requested
501
557
if create_report :
502
558
report_creator (compile_type , log_entry , log_file )
559
+ print '\n Test duration:' , int (toc - tic ), 'sec'
503
560
504
561
def execute_script (self , script , * deps ):
505
562
"""Waits for all JavaScript variables in `deps` to be defined, then
0 commit comments