Skip to content

Commit

Permalink
Mitigate flakiness in iOS (facebook#38894)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#38894

This diff introduces a script `run_with_retry` that we can apply to single commands in order to mitigate the flakiness.

This can be useful when networking is involved, to retry installing some dependencies, or for example with some e2e/integration tests.

The diff applies this rerun to the iOS tests so we mitigate failures in CI.

## Changelog:
[Internal] - Add script to retry CI steps and mitigate iOS flakyness.

Reviewed By: cortinico

Differential Revision: D48189365

fbshipit-source-id: a0e115754bcdb8f8353bb5f070163f8cf8f7c9cf
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Aug 10, 2023
1 parent c5ce508 commit ad18f81
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ jobs:
steps:
- run:
name: "Run Tests: iOS Unit and Integration Tests"
command: yarn test-ios
command: node ./scripts/circleci/run_with_retry.js 3 yarn test-ios
- run:
name: Zip Derived data folder
when: always
Expand Down
40 changes: 40 additions & 0 deletions scripts/circleci/run_with_retry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

const {spawnSync} = require('child_process');

function retryCommand(maxRetries, command) {
for (let i = 1; i <= maxRetries; i++) {
console.log(`Attempt ${i}: ${command}`);
const result = spawnSync(command, {shell: true, stdio: 'inherit'});

if (result.status === 0) {
console.log(`Command succeeded on attempt ${i}`);
process.exit(0);
} else {
console.log(`Command failed on attempt ${i}`);
if (i < maxRetries) {
console.log('Retrying...');
} else {
console.log('Maximum retries reached. Exiting.');
process.exit(1);
}
}
}
}

const maxRetries = process.argv[2];
const command = process.argv.slice(3).join(' ');

if (!maxRetries || !command) {
console.log('Usage: node retry_script.js <max_retries> <command>');
process.exit(1);
}

retryCommand(maxRetries, command);
24 changes: 0 additions & 24 deletions scripts/retry3

This file was deleted.

0 comments on commit ad18f81

Please sign in to comment.