#862 Fix flaky loadtxt test for int32 by adding sleep after savetxt. .#1057
#862 Fix flaky loadtxt test for int32 by adding sleep after savetxt. .#1057punithk-verse wants to merge 1 commit intofortran-lang:masterfrom
Conversation
Added sleep calls to test_loadtxt.f90 to introduce delays between file operations. because before file was being read even before it was writen and closed
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1057 +/- ##
==========================================
+ Coverage 25.12% 25.13% +0.01%
==========================================
Files 570 570
Lines 234201 234201
Branches 41277 41276 -1
==========================================
+ Hits 58838 58871 +33
+ Misses 175363 175330 -33 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR addresses flaky test failures in the loadtxt int32 test by adding 1-second delays after savetxt operations to ensure files are fully written before being read. The race condition occurred when loadtxt attempted to read files before savetxt had finished writing and closing them.
Key changes:
- Added
call sleep(1)statements aftersavetxtcalls in multiple test functions - Applied fix to test_loadtxt_int32, test_loadtxt_sp, test_loadtxt_dp, test_loadtxt_dp_max_skip, test_loadtxt_dp_huge, test_loadtxt_dp_tiny, and test_loadtxt_complex
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| call check(error, all(input == expected),'Default list directed read failed') | ||
| if (allocated(error)) return | ||
| call loadtxt('test_int32.txt', expected, fmt='*') | ||
| call sleep(1) |
There was a problem hiding this comment.
The sleep call is placed after a loadtxt call instead of after a savetxt call. This sleep is unnecessary here since the file has already been written by the savetxt at line 43. The sleep should only be added after savetxt to ensure the file is fully written before reading. Remove this sleep call.
| call sleep(1) |
|
Because the change only affects test routines, and the ongoing onstability of said tests, I am in favor of the PR proposal, although it's not great coding practice. @jvdp1 what do you think? |
|
Thank you @punithk-verse for this PR.
I puzzled with this PR. There are some issues indeed, but I am afraid that this PR will just hide them. Could the intrinsic |
Added sleep calls to test_loadtxt.f90 to introduce delays between file operations. because before file was being read even before it was writeen and closed
Fixes #862
This PR addresses the intermittent failure of the
loadtxttest for int32,which occasionally produced:
End-of-file during read
Root cause:
The test wrote data to 'test_int32.txt' and immediately attempted to read
it with loadtxt.
Fix:
After every call to savetxt, a short delay has been added:
call sleep(1)
This ensures the file is fully written and stable before loadtxt reads it.
This is a beginner-friendly first fix; maintainers may later improve it
using proper file flushing.