Improve test stability in CI (#45070)

Summary:
This change splits the build step and the test step for running the test on iOS, so we can introduce a retry for the test only.
We are doing that because we have seen some flakyness in CI jobs as sometimes the simulator fails to install the app.

## Changelog:
[Internal] - Add retry to iOS tests

Pull Request resolved: https://github.com/facebook/react-native/pull/45070

Test Plan: Testing in CircleCI

Reviewed By: cortinico

Differential Revision: D58786706

Pulled By: cipolleschi

fbshipit-source-id: 61363cb86dd1a496d3595b43b6331cbee7f032ea
This commit is contained in:
Riccardo Cipolleschi 2024-06-20 03:13:13 -07:00 committed by Facebook GitHub Bot
parent e5c7eb57e2
commit bb886d751f

View File

@ -83,6 +83,24 @@ runTests() {
"${SKIPPED_TESTS[@]}"
}
buildForTesting() {
# shellcheck disable=SC1091
source "$ROOT/scripts/.tests.env"
xcodebuild build-for-testing \
-workspace RNTesterPods.xcworkspace \
-scheme RNTester \
-sdk iphonesimulator
}
runTestsOnly() {
xcodebuild test \
-workspace RNTesterPods.xcworkspace \
-scheme RNTester \
-sdk iphonesimulator \
-destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=$IOS_TARGET_OS" \
"${SKIPPED_TESTS[@]}"
}
buildProject() {
xcodebuild build \
-workspace RNTesterPods.xcworkspace \
@ -133,13 +151,33 @@ main() {
preloadBundlesRNTester
preloadBundlesRNIntegrationTests
buildForTesting
# Build and run tests.
if [ -x "$(command -v xcbeautify)" ]; then
runTests | xcbeautifyFormat && exit "${PIPESTATUS[0]}"
else
echo 'Warning: xcbeautify is not installed. Install xcbeautify to generate JUnit reports.'
runTests
fi
RESULT=-1
MAX_RETRY=3
for ((i=1; i<=MAX_RETRY; i++))
do
echo "Attempt #$i of running tests..."
if [ -x "$(command -v xcbeautify)" ]; then
runTests | xcbeautifyFormat && exit "${PIPESTATUS[0]}"
RESULT="$?"
else
echo 'Warning: xcbeautify is not installed. Install xcbeautify to generate JUnit reports.'
runTests
RESULT="$?"
fi
if [[ "$RESULT" == 0 ]]; then
# Successful tests!
echo "Test completed successfully!"
exit 0
fi
done
echo "Test Failed with code $RESULT!"
exit $RESULT
else
# Build without running tests.
if [ -x "$(command -v xcbeautify)" ]; then