From 477489ce847696fd9e9678beda7ab4bd68daf746 Mon Sep 17 00:00:00 2001 From: Mitya Kononchuk Date: Wed, 11 Dec 2024 07:07:10 -0800 Subject: [PATCH] Fix running fantom tests via buck-test (#48215) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48215 Changelog: [internal] Reviewed By: rubennorte Differential Revision: D66976980 fbshipit-source-id: d553c2f702d6928fb0ad88fcc2c6f04160a65d02 --- packages/react-native-fantom/runner/utils.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/react-native-fantom/runner/utils.js b/packages/react-native-fantom/runner/utils.js index 3671f636afb..754aac63f21 100644 --- a/packages/react-native-fantom/runner/utils.js +++ b/packages/react-native-fantom/runner/utils.js @@ -16,6 +16,8 @@ import os from 'os'; // $FlowExpectedError[untyped-import] import {SourceMapConsumer} from 'source-map'; +const BUCK_ISOLATION_DIR = 'react-native-fantom-buck-out'; + export function getBuckModeForPlatform(enableRelease: boolean = false): string { const mode = enableRelease ? 'opt' : 'dev'; @@ -40,6 +42,16 @@ type SpawnResultWithOriginalCommand = { }; export function runBuck2(args: Array): SpawnResultWithOriginalCommand { + // If these tests are already running from withing a buck2 process, e.g. when + // they are scheduled by a `buck2 test` wrapper, calling `buck2` again would + // cause a daemon-level deadlock. + // To prevent this - explicitly pass custom `--isolation-dir`. Reuse the same + // dir across tests (even running in different jest processes) to properly + // employ caching. + if (process.env.BUCK2_WRAPPER != null) { + args.unshift('--isolation-dir', BUCK_ISOLATION_DIR); + } + const result = spawnSync('buck2', args, { encoding: 'utf8', env: {