From 379cbdd8f19ba1e2d85253d16af7287df70a5ea8 Mon Sep 17 00:00:00 2001 From: Christopher Dedominici <18092467+ChristopherDedominici@users.noreply.github.com> Date: Fri, 6 Sep 2024 11:44:13 +0200 Subject: [PATCH] add check to validate that JSON file is fully written --- v-next/hardhat-utils/test/subprocess.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/v-next/hardhat-utils/test/subprocess.ts b/v-next/hardhat-utils/test/subprocess.ts index 6c7e790337..9ee9a50efa 100644 --- a/v-next/hardhat-utils/test/subprocess.ts +++ b/v-next/hardhat-utils/test/subprocess.ts @@ -35,8 +35,12 @@ async function checkIfSubprocessWasExecuted() { counter++; if (await exists(ABSOLUTE_PATH_TO_TMP_RESULT_SUBPROCESS_FILE)) { - clearInterval(intervalId); - resolve(true); + try { + // Wait for the file to be readable. The file could exist but the writing could be in progress. + await readJsonFile(ABSOLUTE_PATH_TO_TMP_RESULT_SUBPROCESS_FILE); + clearInterval(intervalId); + resolve(true); + } catch (_err) {} } else if (counter > MAX_COUNTER) { clearInterval(intervalId); reject("Subprocess was not executed in the expected time");