Skip to content

Commit 7314275

Browse files
byroothsbt
authored andcommitted
json_pure: fix ractor compatibility
This actually never worked, because the test was always testing the ext version from the stdlib, never the pure version nor the current ext version.
1 parent a3c2175 commit 7314275

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

test/json/ractor_test.rb

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99

1010
class JSONInRactorTest < Test::Unit::TestCase
1111
def test_generate
12-
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true)
13-
begin;
14-
$VERBOSE = nil
15-
require "json"
12+
pid = fork do
1613
r = Ractor.new do
1714
json = JSON.generate({
1815
'a' => 2,
@@ -26,9 +23,22 @@ def test_generate
2623
})
2724
JSON.parse(json)
2825
end
29-
expected_json = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
30-
'"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
31-
assert_equal(JSON.parse(expected_json), r.take)
32-
end;
26+
expected_json = JSON.parse('{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
27+
'"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}')
28+
actual_json = r.take
29+
30+
if expected_json == actual_json
31+
exit 0
32+
else
33+
puts "Expected:"
34+
puts expected_json
35+
puts "Acutual:"
36+
puts actual_json
37+
puts
38+
exit 1
39+
end
40+
end
41+
_, status = Process.waitpid2(pid)
42+
assert_predicate status, :success?
3343
end
34-
end if defined?(Ractor)
44+
end if defined?(Ractor) && Process.respond_to?(:fork)

0 commit comments

Comments
 (0)