Run Tests Without Dir.chdir - #52619
Merged
Merged
Conversation
`Dir.chdir` is inherently thread-unsafe, which is a problem for us because the two rake tasks we have which use it also get run in parallel threads: https://github.com/code-dot-org/code-dot-org/blob/e0aa3b37133f99a70f7ff0dffaad9e93da35e286/lib/rake/test.rake#L88-L94 This hasn't harmed us so far because although the two calls to `Dir.chdir` will overwrite one another, they're both in practice targeting the same directory so the "overwritten" one will continue to work just fine. However, Ruby starting in 3.0 will be much more proactive about preventing the user from making this call in the first place and the `test:ui_all` Rake task will begin failing in that version with `conflicting chdir during another chdir block`. Fortunately, we don't actually need to change the working directory at the *Ruby* level, we just want to change the directory from which the child process we're kicking off is executed, which we can do with a simple `cd` in the child process itself. - https://coderscat.com/ruby-change-current-working-directory/ - https://bugs.ruby-lang.org/issues/9785 - https://bugs.ruby-lang.org/issues/15661
Hamms
marked this pull request as ready for review
July 5, 2023 20:48
pablo-code-org
approved these changes
Jul 6, 2023
sureshc
approved these changes
Jul 6, 2023
Hamms
added a commit
that referenced
this pull request
Jul 6, 2023
Hamms
added a commit
that referenced
this pull request
Jul 7, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dir.chdiris inherently thread-unsafe, which is a problem for us because the two rake tasks we have which use it also get run in parallel threads:code-dot-org/lib/rake/test.rake
Lines 88 to 94 in e0aa3b3
This hasn't harmed us so far because although one of the two calls to
Dir.chdirwill "override" the other, they're both targeting the same directory so in practice the overridden one will continue to work just fine.However, Ruby starting in 3.0 will be much more proactive about preventing the user from making this call in the first place and the
test:ui_allRake task will begin failing in that version withconflicting chdir during another chdir block. Fortunately, we don't actually need to change the working directory at the Ruby level, we just want to change the directory from which the child process we're kicking off is executed, which we can do with a simplecdin the child process itself.I recommend reviewing with whitespace changes disabled
Links
Testing story
Verified locally that with this change (plus a tweak to have each test suite run only a single arbitrarily-chosen test rather than the entire test suite), we are successfully able to run
bundle exec rake test:ui_allon Ruby 3.0