Skip to content

Commit 707c222

Browse files
test: Add Flaky Test Plan (#6534)
Add an extra test plan, Sentry_Flaky, that reruns failing tests 3 times before the test officially fails.
1 parent 52588a5 commit 707c222

File tree

7 files changed

+68
-4
lines changed

7 files changed

+68
-4
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ jobs:
373373
run: ./scripts/ci-boot-simulator.sh --xcode ${{ matrix.xcode }} --device "${{ matrix.device }}" --os-version "${{ matrix.test-destination-os }}"
374374

375375
# We split building and running tests in two steps so we know how long running the tests takes.
376-
- name: Build tests
376+
- name: Build Tests
377377
id: build_tests
378378
run: |
379379
./scripts/sentry-xcodebuild.sh \
@@ -385,6 +385,25 @@ jobs:
385385
--configuration TestCI \
386386
--scheme ${{matrix.scheme}}
387387
388+
# Run Flaky Tests TestPlan which has a retry mechanism on failure.
389+
# We intentionally run these before the other test plan to fail early.
390+
# Use a separate result bundle name to avoid conflicts with the regular test run.
391+
# xcodebuild fails if a result bundle already exists at the target path.
392+
- name: Run Flaky Tests
393+
# Only the Sentry Scheme has the Flaky TestPlan.
394+
if: ${{ matrix.scheme == 'Sentry' }}
395+
run: |
396+
./scripts/sentry-xcodebuild.sh \
397+
--platform ${{matrix.platform}} \
398+
--os ${{matrix.test-destination-os}} \
399+
--ref ${{ github.ref_name }} \
400+
--command test-without-building \
401+
--device "${{matrix.device}}" \
402+
--configuration TestCI \
403+
--scheme ${{matrix.scheme}} \
404+
--test-plan Sentry_Flaky \
405+
--result-bundle flaky-results.xcresult
406+
388407
- name: Run tests
389408
# We call a script with the platform so the destination
390409
# passed to xcodebuild doesn't end up in the job name,
@@ -398,7 +417,8 @@ jobs:
398417
--command test-without-building \
399418
--device "${{matrix.device}}" \
400419
--configuration TestCI \
401-
--scheme ${{matrix.scheme}}
420+
--scheme ${{matrix.scheme}} \
421+
--result-bundle results.xcresult
402422
403423
- name: Publish Test Report
404424
uses: mikepenz/action-junit-report@3585e9575db828022551b4231f165eb59a0e74e3 # v5.6.2
@@ -442,6 +462,7 @@ jobs:
442462
name: result-bundle-${{matrix.platform}}-xcode-${{matrix.xcode}}-os-${{matrix.test-destination-os}}
443463
path: |
444464
results.xcresult
465+
flaky-results.xcresult
445466
446467
- name: Gather code coverage information via slather
447468
run: slather coverage --configuration TestCI --scheme Sentry

Plans/Sentry_Base.xctestplan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"SentryCrashReportStore_Tests\/testCrashReportCount1",
3636
"SentryCrashReportStore_Tests\/testDeleteAllReports",
3737
"SentryCrashReportStore_Tests\/testStoresLoadsMultipleReports",
38+
"SentryHttpTransportFlushIntegrationTests",
3839
"SentryHttpTransportTests\/testFlush_WhenNoInternet_BlocksAndFinishes()",
3940
"SentryNetworkTrackerIntegrationTestServerTests",
4041
"SentryNetworkTrackerIntegrationTestServerTests\/testGetRequest_SpanCreatedAndBaggageHeaderAdded()",

Plans/Sentry_Flaky.xctestplan

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"configurations" : [
3+
{
4+
"id" : "A451EF21-C702-4095-835C-4F189D10635A",
5+
"name" : "Configuration 1",
6+
"options" : {
7+
8+
}
9+
}
10+
],
11+
"defaultOptions" : {
12+
"testExecutionOrdering" : "random",
13+
"testRepetitionMode" : "retryOnFailure",
14+
"testTimeoutsEnabled" : true
15+
},
16+
"testTargets" : [
17+
{
18+
"selectedTests" : [
19+
"SentryHttpTransportFlushIntegrationTests"
20+
],
21+
"target" : {
22+
"containerPath" : "container:Sentry.xcodeproj",
23+
"identifier" : "63AA76641EB8CB2F00D153DE",
24+
"name" : "SentryTests"
25+
}
26+
}
27+
],
28+
"version" : 1
29+
}

Sentry.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,7 @@
13891389
6293F5742D422A8A002BC3BD /* SentryStacktraceCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryStacktraceCodable.swift; sourceTree = "<group>"; };
13901390
62950F0F29E7FE0100A42624 /* SentryTransactionContextTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTransactionContextTests.swift; sourceTree = "<group>"; };
13911391
629690522AD3E060000185FA /* SentryReachabilitySwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryReachabilitySwiftTests.swift; sourceTree = "<group>"; };
1392+
629B24502EAB50C70050052C /* Sentry_Flaky.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Sentry_Flaky.xctestplan; sourceTree = "<group>"; };
13921393
62A3C7BD2B7E2A6A00C75227 /* SentrySpotlightTransportTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySpotlightTransportTests.swift; sourceTree = "<group>"; };
13931394
62A456E02B03704A003F19A1 /* SentryUIEventTrackerMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryUIEventTrackerMode.h; path = include/SentryUIEventTrackerMode.h; sourceTree = "<group>"; };
13941395
62A456E22B0370AA003F19A1 /* SentryUIEventTrackerTransactionMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryUIEventTrackerTransactionMode.h; path = include/SentryUIEventTrackerTransactionMode.h; sourceTree = "<group>"; };
@@ -4310,6 +4311,7 @@
43104311
isa = PBXGroup;
43114312
children = (
43124313
D46D45E12D5F3FD600A1CB35 /* Sentry_Base.xctestplan */,
4314+
629B24502EAB50C70050052C /* Sentry_Flaky.xctestplan */,
43134315
6214366A2E7A7D6600A2CB8F /* Sentry_TestServer.xctestplan */,
43144316
D46D45E92D5F411700A1CB35 /* SentrySwiftUI_Base.xctestplan */,
43154317
D4A2360A2D5F84FA00D55C58 /* SwiftUITestSample_Base.xctestplan */,

Sentry.xcodeproj/xcshareddata/xcschemes/Sentry.xcscheme

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
<TestPlanReference
5353
reference = "container:Plans/Sentry_TestServer.xctestplan">
5454
</TestPlanReference>
55+
<TestPlanReference
56+
reference = "container:Plans/Sentry_Flaky.xctestplan">
57+
</TestPlanReference>
5558
</TestPlans>
5659
<Testables>
5760
<TestableReference

develop-docs/TEST.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ Once daily and for every PR via [Github action](../.github/workflows/benchmarkin
133133

134134
### Flaky tests
135135

136-
If you see a test being flaky, you should ideally fix it immediately. If that's not feasible, you can disable the test in the test scheme by unchecking it in the associated test plan:
136+
If you see a test being flaky, you should ideally fix it immediately. If that's not feasible, you can add it to the Sentry_Flaky test plan and remove it from the SentryBase test plan. The Sentry_Flaky test plan has a retry mechanism of 3 times until a test officially fails.
137+
138+
Or you disable the test in the test scheme by unchecking it in the associated test plan:
137139

138140
![Disabling test cases via the Xcode Tests navigator](./develop-docs/disabling_tests_xcode_test_plan.png)
139141

scripts/sentry-xcodebuild.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CONFIGURATION_OVERRIDE=""
2222
DERIVED_DATA_PATH=""
2323
TEST_SCHEME="Sentry"
2424
TEST_PLAN=""
25+
RESULT_BUNDLE_PATH="results.xcresult"
2526

2627
usage() {
2728
echo "Usage: $0"
@@ -34,6 +35,7 @@ usage() {
3435
echo " -D|--derived-data <path> Derived data path"
3536
echo " -s|--scheme <scheme> Test scheme (default: Sentry)"
3637
echo " -t|--test-plan <plan> Test plan name (default: empty)"
38+
echo " -R|--result-bundle <path> Result bundle path (default: results.xcresult)"
3739
exit 1
3840
}
3941

@@ -76,6 +78,10 @@ while [[ $# -gt 0 ]]; do
7678
TEST_PLAN="$2"
7779
shift 2
7880
;;
81+
-R|--result-bundle)
82+
RESULT_BUNDLE_PATH="$2"
83+
shift 2
84+
;;
7985
*)
8086
echo "Unknown option: $1"
8187
usage
@@ -188,7 +194,7 @@ if [ $RUN_TEST_WITHOUT_BUILDING == true ]; then
188194
"${TEST_PLAN_ARGS[@]+${TEST_PLAN_ARGS[@]}}" \
189195
-configuration "$CONFIGURATION" \
190196
-destination "$DESTINATION" \
191-
-resultBundlePath "results.xcresult" \
197+
-resultBundlePath "$RESULT_BUNDLE_PATH" \
192198
test-without-building 2>&1 |
193199
tee raw-test-output.log |
194200
xcbeautify --report junit

0 commit comments

Comments
 (0)