@@ -113,48 +113,79 @@ function stopDuplicates {
113113}
114114stopDuplicates
115115
116- # Schedule the test run in device farm
117- echo " Scheduling test run"
118- run_arn=` aws devicefarm schedule-run --project-arn=$project_arn \
119- --app-arn=" $app_package_upload_arn " \
120- --device-selection-configuration=' {
121- "filters": [
122- {"attribute": "ARN", "operator":"IN", "values":["' $minDevice ' ", "' $middleDevice ' ", "' $latestDevice ' "]}
123- ],
124- "maxDevices": ' $max_devices '
125- }' \
126- --name=" $file_name -$commit_sha " \
127- --test=" testSpecArn=$test_spec_arn ,type=INSTRUMENTATION,testPackageArn=$test_package_upload_arn " \
128- --execution-configuration=" jobTimeoutMinutes=30,videoCapture=false" \
129- --query=" run.arn" \
130- --output=text \
131- --region=" us-west-2" `
132-
133- status=' NONE'
134- result=' NONE'
135- # Wait for the test to complete
136- while true ; do
137- run_status_response=` aws devicefarm get-run --arn=" $run_arn " --region=" us-west-2" --query=" run.[status, result]" --output text`
138- read -a result_arr <<< $run_status_response
139- status=${result_arr[0]}
140- result=${result_arr[1]}
141- if [ " $status " = " COMPLETED" ]
142- then
116+ # Most modules complete within 30 minutes
117+ job_timeout=30
118+
119+ # Retry the Device Farm test run on failure. Transient issues like DNS
120+ # flakes, auth credential races, or process crashes on shared Device Farm
121+ # devices usually pass on a second attempt.
122+ max_run_attempts=2
123+ final_result=' NONE'
124+
125+ for run_attempt in $( seq 1 $max_run_attempts ) ; do
126+ echo " ============================================================"
127+ echo " [RUN_IN_DEVICEFARM] Attempt $run_attempt /$max_run_attempts for $module_name "
128+ echo " ============================================================"
129+
130+ echo " [RUN_IN_DEVICEFARM] Scheduling test run..."
131+ run_arn=` aws devicefarm schedule-run --project-arn=$project_arn \
132+ --app-arn=" $app_package_upload_arn " \
133+ --device-selection-configuration=' {
134+ "filters": [
135+ {"attribute": "ARN", "operator":"IN", "values":["' $minDevice ' ", "' $middleDevice ' ", "' $latestDevice ' "]}
136+ ],
137+ "maxDevices": ' $max_devices '
138+ }' \
139+ --name=" $file_name -$commit_sha " \
140+ --test=" testSpecArn=$test_spec_arn ,type=INSTRUMENTATION,testPackageArn=$test_package_upload_arn " \
141+ --execution-configuration=" jobTimeoutMinutes=$job_timeout ,videoCapture=false" \
142+ --query=" run.arn" \
143+ --output=text \
144+ --region=" us-west-2" `
145+
146+ echo " [RUN_IN_DEVICEFARM] Run ARN: $run_arn "
147+ echo " [RUN_IN_DEVICEFARM] Waiting for test run to complete..."
148+
149+ status=' NONE'
150+ result=' NONE'
151+ while true ; do
152+ run_status_response=` aws devicefarm get-run --arn=" $run_arn " --region=" us-west-2" --query=" run.[status, result]" --output text`
153+ read -a result_arr <<< $run_status_response
154+ status=${result_arr[0]}
155+ result=${result_arr[1]}
156+ if [ " $status " = " COMPLETED" ]; then
157+ break
158+ fi
159+ sleep 30
160+ done
161+
162+ final_result=$result
163+ echo " [RUN_IN_DEVICEFARM] Attempt $run_attempt /$max_run_attempts : Status=$status Result=$result "
164+
165+ if [ " $result " = " PASSED" ]; then
166+ if [ $run_attempt -gt 1 ]; then
167+ echo " [RUN_IN_DEVICEFARM] Tests passed on retry (attempt $run_attempt )"
168+ fi
143169 break
144170 fi
145- sleep 30
171+
172+ if [ $run_attempt -lt $max_run_attempts ]; then
173+ echo " [RUN_IN_DEVICEFARM] Tests did not pass (result=$result ). Will retry..."
174+ else
175+ echo " [RUN_IN_DEVICEFARM] Tests did not pass after $max_run_attempts attempts."
176+ fi
146177done
147- echo " Status = $status Result = $result "
178+
179+ echo " ============================================================"
180+ echo " [RUN_IN_DEVICEFARM] Final result for $module_name : $final_result "
181+ echo " ============================================================"
148182
149183./scripts/python/generate_df_testrun_report.py \
150184 -r " $run_arn " \
151185 -m " $module_name " \
152186 -o " build/allTests/$module_name /"
153187
154- # If the result is PASSED, then exit with a return code 0
155- if [ " $result " = " PASSED" ]
156- then
188+ if [ " $final_result " = " PASSED" ]; then
157189 exit 0
158190fi
159- # Otherwise, exit with a non-zero.
160191exit 1
0 commit comments