Skip to content

Commit 60895cd

Browse files
Revert "use async queue instead of ruby array at helper spec"
This reverts commit 528ee15.
1 parent 528ee15 commit 60895cd

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

spec/dummy/spec/helpers/react_on_rails_pro_helper_spec.rb

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require "async"
4-
require "async/queue"
53
require "rails_helper"
64
require "support/script_tag_utils"
75

@@ -305,7 +303,7 @@ def response; end
305303
{ html: "<div>Chunk 3: Final content</div>", consoleReplayScript: "" }
306304
]
307305
end
308-
let(:chunks_read) { Async::Queue.new }
306+
let(:chunks_read) { [] }
309307
let(:react_component_specification_tag) do
310308
<<-SCRIPT.strip_heredoc
311309
<script type="application/json"
@@ -338,7 +336,7 @@ def mock_request_and_response(mock_chunks = chunks, count: 1)
338336
end
339337
clear_stream_mocks
340338

341-
chunks_read.dequeue until chunks_read.empty?
339+
chunks_read.clear
342340
mock_streaming_response(%r{http://localhost:3800/bundles/[a-f0-9]{32}-test/render/[a-f0-9]{32}}, 200,
343341
count: count) do |yielder|
344342
mock_chunks.each do |chunk|
@@ -364,7 +362,7 @@ def mock_request_and_response(mock_chunks = chunks, count: 1)
364362
expect(initial_result).to include(react_component_div_with_initial_chunk)
365363
expect(initial_result).to include(chunks.first[:consoleReplayScript])
366364
expect(initial_result).not_to include("More content", "Final content")
367-
expect(chunks_read.size).to eq(1)
365+
expect(chunks_read.count).to eq(1)
368366
end
369367

370368
it "creates a fiber to read subsequent chunks" do
@@ -380,16 +378,16 @@ def mock_request_and_response(mock_chunks = chunks, count: 1)
380378
/#{Regexp.escape(chunks[1][:html])}\s+#{Regexp.escape(chunks[1][:consoleReplayScript])}/
381379
)
382380
expect(second_result).not_to include("Stream React Server Components", "Final content")
383-
expect(chunks_read.size).to eq(2)
381+
expect(chunks_read.count).to eq(2)
384382

385383
third_result = fiber.resume
386384
expect(third_result).to eq(chunks[2][:html].to_s)
387385
expect(third_result).not_to include("Stream React Server Components", "More content")
388-
expect(chunks_read.size).to eq(3)
386+
expect(chunks_read.count).to eq(3)
389387

390388
expect(fiber.resume).to be_nil
391389
expect(fiber).not_to be_alive
392-
expect(chunks_read.size).to eq(chunks.count)
390+
expect(chunks_read.count).to eq(chunks.count)
393391
end
394392

395393
it "does not trim whitespaces from html" do
@@ -431,7 +429,7 @@ def mock_request_and_response(mock_chunks = chunks, count: 1)
431429
allow(mocked_stream).to receive(:write) do |chunk|
432430
written_chunks << chunk
433431
# Ensures that any chunk received is written immediately to the stream
434-
expect(written_chunks.count).to eq(chunks_read.size) # rubocop:disable RSpec/ExpectInHook
432+
expect(written_chunks.count).to eq(chunks_read.count) # rubocop:disable RSpec/ExpectInHook
435433
end
436434
allow(mocked_stream).to receive(:close)
437435
mocked_response = instance_double(ActionDispatch::Response)
@@ -443,7 +441,7 @@ def mock_request_and_response(mock_chunks = chunks, count: 1)
443441
it "writes the chunk to stream as soon as it is received" do
444442
stream_view_containing_react_components(template: template_path)
445443
expect(self).to have_received(:render_to_string).once.with(template: template_path)
446-
expect(chunks_read.size).to eq(chunks.count)
444+
expect(chunks_read.count).to eq(chunks.count)
447445
expect(written_chunks.count).to eq(chunks.count)
448446
expect(mocked_stream).to have_received(:write).exactly(chunks.count).times
449447
expect(mocked_stream).to have_received(:close)
@@ -548,7 +546,7 @@ def stub_render_with_cached_stream(cache_key:, props:, **opts)
548546

549547
def reset_stream_buffers
550548
written_chunks.clear
551-
chunks_read.dequeue until chunks_read.empty?
549+
chunks_read.clear
552550
end
553551

554552
def run_stream
@@ -565,15 +563,15 @@ def run_stream
565563

566564
# First render (MISS → write-through)
567565
first_run_chunks = run_stream
568-
expect(chunks_read.size).to eq(chunks.count)
566+
expect(chunks_read.count).to eq(chunks.count)
569567
expect(first_run_chunks.first).to include("<h1>Header Rendered In View</h1>")
570568

571569
# Second render (HIT → served from cache, no Node call; no new HTTPX chunks)
572570
reset_stream_buffers
573571
# Reset rails context flag to simulate a fresh request lifecycle
574572
@rendered_rails_context = nil
575573
second_run_chunks = run_stream
576-
expect(chunks_read.size).to eq(0)
574+
expect(chunks_read.count).to eq(0)
577575
expect(second_run_chunks).to eq(first_run_chunks)
578576
end
579577

@@ -586,15 +584,15 @@ def run_stream
586584

587585
# First render
588586
run_stream
589-
first_call_count = chunks_read.size
587+
first_call_count = chunks_read.count
590588
expect(first_call_count).to eq(chunks.count)
591589

592590
# Second render (still goes to Node)
593591
reset_stream_buffers
594592
run_stream
595593
reset_stream_buffers
596594
run_stream
597-
expect(chunks_read.size).to eq(chunks.count)
595+
expect(chunks_read.count).to eq(chunks.count)
598596
end
599597

600598
it "invalidates cache when props change" do
@@ -636,13 +634,13 @@ def run_stream
636634
# With if: false, caching should be disabled - both calls hit Node renderer
637635
render_with_cached_stream(if: false)
638636
first_run_chunks = run_stream
639-
expect(chunks_read.size).to eq(chunks.count)
637+
expect(chunks_read.count).to eq(chunks.count)
640638

641639
reset_stream_buffers
642640
@rendered_rails_context = nil
643641
render_with_cached_stream(if: false)
644642
second_run_chunks = run_stream
645-
expect(chunks_read.size).to eq(chunks.count) # Both calls went to Node
643+
expect(chunks_read.count).to eq(chunks.count) # Both calls went to Node
646644

647645
expect(second_run_chunks).to eq(first_run_chunks) # Same template/props, same result
648646
end

0 commit comments

Comments
 (0)