22
22
sys .exit (1 )
23
23
PROJECT = os .environ ['GCP_PROJECT' ]
24
24
25
+ # Exit codes returned by the FTL command that signal an infrastructure failure.
26
+ FTL_INFRA_FAILURE_CODES = [1 , 15 , 20 ]
27
+
28
+ # Maximum number of retries done if an infrastructure failure occurs.
29
+ MAX_RETRY_ATTEMPTS = 2
30
+
25
31
script_dir = os .path .dirname (os .path .realpath (__file__ ))
26
32
buildroot_dir = os .path .abspath (os .path .join (script_dir , '..' , '..' ))
27
33
out_dir = os .path .join (buildroot_dir , 'out' )
@@ -54,7 +60,7 @@ def run_firebase_test(apk, results_dir):
54
60
'--results-dir' ,
55
61
results_dir ,
56
62
'--device' ,
57
- 'model=panther ,version=33 ' ,
63
+ 'model=shiba ,version=34 ' ,
58
64
],
59
65
stdout = subprocess .PIPE ,
60
66
stderr = subprocess .STDOUT ,
@@ -106,7 +112,7 @@ def main():
106
112
args = parser .parse_args ()
107
113
108
114
apks_dir = os .path .join (out_dir , args .variant , 'firebase_apks' )
109
- apks = glob .glob ('%s/*.apk' % apks_dir )
115
+ apks = set ( glob .glob ('%s/*.apk' % apks_dir ) )
110
116
111
117
if not apks :
112
118
print ('No APKs found at %s' % apks_dir )
@@ -115,27 +121,41 @@ def main():
115
121
git_revision = subprocess .check_output (['git' , 'rev-parse' , 'HEAD' ], cwd = script_dir )
116
122
git_revision = byte_str_decode (git_revision )
117
123
git_revision = git_revision .strip ()
118
- results = []
119
- apk = None
120
- for apk in apks :
121
- results_dir = '%s/%s/%s' % (os .path .basename (apk ), git_revision , args .build_id )
122
- process = run_firebase_test (apk , results_dir )
123
- results .append ((results_dir , process ))
124
-
125
- for results_dir , process in results :
126
- for line in iter (process .stdout .readline , '' ):
127
- print (line .strip ())
128
- return_code = process .wait ()
129
- if return_code != 0 :
130
- print ('Firebase test failed with code: %s' % return_code )
131
- sys .exit (return_code )
132
-
133
- print ('Checking logcat for %s' % results_dir )
134
- check_logcat (results_dir )
135
- # scenario_app produces a timeline, but the android image test does not.
136
- if 'scenario' in apk :
137
- print ('Checking timeline for %s' % results_dir )
138
- check_timeline (results_dir )
124
+
125
+ for retry in range (MAX_RETRY_ATTEMPTS ):
126
+ if retry > 0 :
127
+ print ('Retrying %s' % apks )
128
+
129
+ results = []
130
+ for apk in sorted (apks ):
131
+ results_dir = '%s/%s/%s' % (os .path .basename (apk ), git_revision , args .build_id )
132
+ process = run_firebase_test (apk , results_dir )
133
+ results .append ((apk , results_dir , process ))
134
+
135
+ for apk , results_dir , process in results :
136
+ print ('===== Test output for %s' % apk )
137
+ for line in iter (process .stdout .readline , '' ):
138
+ print (line .strip ())
139
+
140
+ return_code = process .wait ()
141
+ if return_code in FTL_INFRA_FAILURE_CODES :
142
+ print ('Firebase test %s failed with infrastructure error code: %s' % (apk , return_code ))
143
+ continue
144
+ if return_code != 0 :
145
+ print ('Firebase test %s failed with code: %s' % (apk , return_code ))
146
+ sys .exit (return_code )
147
+
148
+ print ('Checking logcat for %s' % results_dir )
149
+ check_logcat (results_dir )
150
+ # scenario_app produces a timeline, but the android image test does not.
151
+ if 'scenario' in apk :
152
+ print ('Checking timeline for %s' % results_dir )
153
+ check_timeline (results_dir )
154
+
155
+ apks .remove (apk )
156
+
157
+ if not apks :
158
+ break
139
159
140
160
return 0
141
161
0 commit comments