Skip to content

Commit bb886d7

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Improve test stability in CI (facebook#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: facebook#45070 Test Plan: Testing in CircleCI Reviewed By: cortinico Differential Revision: D58786706 Pulled By: cipolleschi fbshipit-source-id: 61363cb86dd1a496d3595b43b6331cbee7f032ea
1 parent e5c7eb5 commit bb886d7

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

scripts/objc-test.sh

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,24 @@ runTests() {
8383
"${SKIPPED_TESTS[@]}"
8484
}
8585

86+
buildForTesting() {
87+
# shellcheck disable=SC1091
88+
source "$ROOT/scripts/.tests.env"
89+
xcodebuild build-for-testing \
90+
-workspace RNTesterPods.xcworkspace \
91+
-scheme RNTester \
92+
-sdk iphonesimulator
93+
}
94+
95+
runTestsOnly() {
96+
xcodebuild test \
97+
-workspace RNTesterPods.xcworkspace \
98+
-scheme RNTester \
99+
-sdk iphonesimulator \
100+
-destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=$IOS_TARGET_OS" \
101+
"${SKIPPED_TESTS[@]}"
102+
}
103+
86104
buildProject() {
87105
xcodebuild build \
88106
-workspace RNTesterPods.xcworkspace \
@@ -133,13 +151,33 @@ main() {
133151
preloadBundlesRNTester
134152
preloadBundlesRNIntegrationTests
135153

154+
buildForTesting
155+
136156
# Build and run tests.
137-
if [ -x "$(command -v xcbeautify)" ]; then
138-
runTests | xcbeautifyFormat && exit "${PIPESTATUS[0]}"
139-
else
140-
echo 'Warning: xcbeautify is not installed. Install xcbeautify to generate JUnit reports.'
141-
runTests
142-
fi
157+
RESULT=-1
158+
MAX_RETRY=3
159+
for ((i=1; i<=MAX_RETRY; i++))
160+
do
161+
echo "Attempt #$i of running tests..."
162+
if [ -x "$(command -v xcbeautify)" ]; then
163+
runTests | xcbeautifyFormat && exit "${PIPESTATUS[0]}"
164+
RESULT="$?"
165+
else
166+
echo 'Warning: xcbeautify is not installed. Install xcbeautify to generate JUnit reports.'
167+
runTests
168+
RESULT="$?"
169+
fi
170+
171+
if [[ "$RESULT" == 0 ]]; then
172+
# Successful tests!
173+
echo "Test completed successfully!"
174+
exit 0
175+
fi
176+
done
177+
178+
echo "Test Failed with code $RESULT!"
179+
exit $RESULT
180+
143181
else
144182
# Build without running tests.
145183
if [ -x "$(command -v xcbeautify)" ]; then

0 commit comments

Comments
 (0)