Skip to content

Commit

Permalink
Fix parallel result of nil
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Mar 5, 2024
1 parent dc81eb6 commit 98b433c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/mutant/parallel/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def self.read_response(**attributes)
def read_till_final
readers = [response_reader, log_reader]

until result || error
until !@results.empty? || error
status = deadline.status

break timeout unless status.ok?
Expand Down
18 changes: 9 additions & 9 deletions spec/integration/mutant/parallel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ def status
[
Mutant::Parallel::Response.new(
error: nil,
output: "Booting: 0\nPayload: 1\n",
log: "Booting: 0\nPayload: 1\n",
result: 2
),
Mutant::Parallel::Response.new(
error: nil,
output: "Payload: 2\n",
log: "Payload: 2\n",
result: 4
),
Mutant::Parallel::Response.new(
error: nil,
output: "Payload: 3\n",
log: "Payload: 3\n",
result: 6
)
]
Expand Down Expand Up @@ -98,10 +98,10 @@ def status

response_a, response_b = responses

expect(response_a).to eql(Mutant::Parallel::Response.new(output: '', result: nil, error: nil))
expect(response_a).to eql(Mutant::Parallel::Response.new(log: '', result: nil, error: nil))
expect(response_b.error).to be(EOFError)
expect(response_b.result).to be(nil)
expect(response_b.output.match?('<main>')).to be(true)
expect(response_b.log.match?('<main>')).to be(true)
end

specify 'massive' do
Expand Down Expand Up @@ -134,12 +134,12 @@ def status
[
Mutant::Parallel::Response.new(
error: nil,
output: "#{b}\n#{b}\n",
log: "#{b}\n#{b}\n",
result: b
),
Mutant::Parallel::Response.new(
error: nil,
output: "#{b}#{b}\n",
log: "#{b}#{b}\n",
result: b * 2
)
]
Expand Down Expand Up @@ -175,7 +175,7 @@ def status
expect(responses.length).to be(3)

responses.each do |response|
expect(response.output.match?(/<iteration \d+>/)).to be(true)
expect(response.log.match?(/<iteration \d+>/)).to be(true)
end
end

Expand Down Expand Up @@ -233,7 +233,7 @@ def status
expect(sink.status).to eql(
[
Mutant::Parallel::Response.new(
output: '',
log: '',
result: nil,
error: Timeout
)
Expand Down
33 changes: 33 additions & 0 deletions spec/unit/mutant/parallel/connection/reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,39 @@ def marshal_load
end

context 'on result' do
context 'with nil result' do
let(:result) { nil }

let(:raw_expectations) do
[
deadline_status,
select([response_reader]),
binmode(response_reader),
read(io: response_reader, bytes: 4, chunk: header_segment),
deadline_status,
select([response_reader]),
binmode(response_reader),
read(
bytes: result_segment.bytesize,
chunk: result_segment,
io: response_reader
),
marshal_load
]
end

it 'returns parallel result' do
verify_events do
expect(apply).to eql(
Mutant::Parallel::Response.new(
error: nil,
log: '',
result: result
)
)
end
end
end
context 'with full reads' do
let(:raw_expectations) do
[
Expand Down

0 comments on commit 98b433c

Please sign in to comment.