Skip to content

Conversation

luke-gruber
Copy link

No description provided.

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

Call to Kernel.open with a non-constant value. Consider replacing it with File.open.

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.

Suggested changeset 1
test/ruby/test_whileuntil.rb

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/ruby/test_whileuntil.rb b/test/ruby/test_whileuntil.rb
--- a/test/ruby/test_whileuntil.rb
+++ b/test/ruby/test_whileuntil.rb
@@ -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)
EOF
@@ -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)
Copilot is powered by AI and may make mistakes. Always verify output.
@luke-gruber luke-gruber force-pushed the test_all_ractors_multi_ractor branch from 4a3a2d7 to f3aa1ea Compare August 12, 2025 17:45
@peterzhu2118 peterzhu2118 force-pushed the test_all_ractors_multi_ractor branch from 88d6f7b to 8048328 Compare August 18, 2025 13:51
@luke-gruber luke-gruber force-pushed the test_all_ractors_multi_ractor branch 9 times, most recently from 55d9388 to ca12e17 Compare September 29, 2025 17:34
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.
@luke-gruber luke-gruber force-pushed the test_all_ractors_multi_ractor branch from ca12e17 to c25554d Compare September 29, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant