diff options
| author | Jay Kwak <82421531+jkwak-work@users.noreply.github.com> | 2025-10-14 17:07:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-15 00:07:03 +0000 |
| commit | 05cae938cbe1ac8807f4913044d9bee46dc3a0e1 (patch) | |
| tree | 6eec1865f6c17390e39a7e61a9b7519605cc4cdc /tools | |
| parent | b173149f4f48b5331ebd3c3643f9449c7a29d72e (diff) | |
Retry file reads in slang-test to handle intermittent I/O errors (#8713)
Related #8705
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 36e79659f..0095a5867 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -557,13 +557,43 @@ static SlangResult _gatherTestsForFile( String fileContents; - SlangResult readResult = Slang::File::readAllText(filePath, fileContents); + TestReporter* testReporter = nullptr; + if (context) + testReporter = context->getTestReporter(); + + // Try reading the file with retries on failure to handle intermittent I/O errors + // (commonly seen on macOS in CI environments) + SlangResult readResult = SLANG_FAIL; + for (int retryCount = 0; retryCount < 3 && SLANG_FAILED(readResult); ++retryCount) + { + if (retryCount) + { + if (testReporter) + { + testReporter->messageFormat( + TestMessageType::Info, + "Retrying to read test file '%s' (attempt %d)", + filePath.getBuffer(), + retryCount + 1); + } + else + { + fprintf( + stderr, + "Retrying to read test file '%s' (attempt %d)\n", + filePath.getBuffer(), + retryCount + 1); + } + std::this_thread::sleep_for(std::chrono::milliseconds(retryCount * 100)); + } + readResult = Slang::File::readAllText(filePath, fileContents); + } if (SLANG_FAILED(readResult)) { // Log file reading failure with details (thread-safe) - if (context && context->getTestReporter()) + if (testReporter) { - context->getTestReporter()->messageFormat( + testReporter->messageFormat( TestMessageType::RunError, "Failed to read test file '%s' (error: 0x%08X)", filePath.getBuffer(), |
