-
Notifications
You must be signed in to change notification settings - Fork 14
Test all ractors multi ractor #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
assert_no_match(/Amiga/, line) | ||
assert_no_match(/paper/, line) | ||
if main_ractor? | ||
tmp = open(tmpfilename, "r") |
Check failure
Code scanning / CodeQL
Use of `Kernel.open` or `IO.read` or similar sinks with a non-constant value Critical test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
The best way to fix this problem is to replace all instances of open(tmpfilename, ...)
with File.open(tmpfilename, ...)
. This ensures that the file is opened directly, and Ruby will not interpret the filename as a shell command, even if it starts with a |
. The change should be made in all places within the shown code where open
is called with a variable filename. No additional imports or method definitions are needed, as File
is part of Ruby's core library.
-
Copy modified line R10 -
Copy modified line R18 -
Copy modified line R29 -
Copy modified line R38 -
Copy modified line R63
@@ -7,7 +7,7 @@ | ||
Dir.mktmpdir("ruby_while_tmp") {|tmpdir| | ||
tmpfilename = "#{tmpdir}/ruby_while_tmp.#{$$}" | ||
|
||
tmp = open(tmpfilename, "w") | ||
tmp = File.open(tmpfilename, "w") | ||
tmp.print "tvi925\n"; | ||
tmp.print "tvi920\n"; | ||
tmp.print "vt100\n"; | ||
@@ -15,7 +15,7 @@ | ||
tmp.print "paper\n"; | ||
tmp.close | ||
|
||
tmp = open(tmpfilename, "r") | ||
tmp = File.open(tmpfilename, "r") | ||
assert_instance_of(File, tmp) | ||
|
||
while line = tmp.gets() | ||
@@ -26,7 +26,7 @@ | ||
assert_match(/vt100/, line) | ||
tmp.close | ||
|
||
tmp = open(tmpfilename, "r") | ||
tmp = File.open(tmpfilename, "r") | ||
while line = tmp.gets() | ||
next if /vt100/ =~ line | ||
assert_no_match(/vt100/, line) | ||
@@ -35,7 +35,7 @@ | ||
assert_no_match(/vt100/, line) | ||
tmp.close | ||
|
||
tmp = open(tmpfilename, "r") | ||
tmp = File.open(tmpfilename, "r") | ||
while line = tmp.gets() | ||
lastline = line | ||
line = line.gsub(/vt100/, 'VT100') | ||
@@ -60,7 +60,7 @@ | ||
assert_equal(220, sum) | ||
|
||
if main_ractor? | ||
tmp = open(tmpfilename, "r") | ||
tmp = File.open(tmpfilename, "r") | ||
while line = tmp.gets() | ||
break if $. == 3 | ||
assert_no_match(/vt100/, line) |
4a3a2d7
to
f3aa1ea
Compare
88d6f7b
to
8048328
Compare
55d9388
to
ca12e17
Compare
This tests for ractor safety issues as well as concurrency issues. You can enable these tests with RUBY_TESTS_WITH_RACTORS=X when running `make test-all TESTS=test/ruby`. Running tests with ractors is currently only working for tests under the "test/ruby" directory. You should also use the `.excludes-ractor` excludes directory. For example: ``` EXCLUDES=test/.excludes-ractor RUBY_TESTS_WITH_RACTORS=3 TESTS=test/ruby make test-all ``` This will create 3 ractors for each test method, run the test method inside each ractor and then call `join` on the ractors. Then, it's ready to process the next test. The reason we do this instead of taking all the tests and dividing them between the number of ractors is: * We want to run each test under concurrency load to test whether or not it is safe under ractors. If it isn't safe, we know it's something to do with this specific test. * If we get a segfault or error, we know the error is coming from this test alone, not interactions with other tests. The disadvantage of this approach is: * It's slower than dividing the tests between the number of ractors running. * This might not uncover ractor scheduling issues that would show up when you have long-running ractors.
ca12e17
to
c25554d
Compare
No description provided.