-
Notifications
You must be signed in to change notification settings - Fork 39
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
Ensure handle_demand busy wait infinite loop doesn't occur & deprecate message_child #779
Changes from 7 commits
4a24e93
150069c
f4be83d
430933d
ee7cf48
b40b1e4
d1068aa
bd5f8f3
06ac9c9
a83dd86
f712328
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,79 @@ | ||||
defmodule Membrane.Test.DelayedDemandsLoopTest do | ||||
use ExUnit.Case, async: true | ||||
|
||||
import Membrane.ChildrenSpec | ||||
import Membrane.Testing.Assertions | ||||
|
||||
alias Membrane.Buffer | ||||
alias Membrane.Debug | ||||
alias Membrane.Testing | ||||
|
||||
defmodule Source do | ||||
use Membrane.Source | ||||
|
||||
defmodule StreamFormat do | ||||
defstruct [] | ||||
end | ||||
|
||||
@sleep_time 5 | ||||
|
||||
def_output_pad :output, | ||||
accepted_format: _any, | ||||
availability: :on_request, | ||||
flow_control: :manual | ||||
|
||||
@impl true | ||||
def handle_demand(_pad, _size, :buffers, %{pads: pads}, state) do | ||||
Process.sleep(@sleep_time) | ||||
|
||||
stream_format_actions = | ||||
Enum.flat_map(pads, fn | ||||
{pad_ref, %{start_of_stream?: false}} -> [stream_format: {pad_ref, %StreamFormat{}}] | ||||
_pad_entry -> [] | ||||
end) | ||||
|
||||
buffer = %Buffer{payload: "a"} | ||||
|
||||
buffer_and_redemand_actions = | ||||
Map.keys(pads) | ||||
|> Enum.flat_map(&[buffer: {&1, buffer}, redemand: &1]) | ||||
|
||||
{stream_format_actions ++ buffer_and_redemand_actions, state} | ||||
end | ||||
|
||||
@impl true | ||||
def handle_parent_notification(:request, _ctx, state) do | ||||
{[notify_parent: :response], state} | ||||
end | ||||
end | ||||
|
||||
describe "delayed demands loop pauses from time to time, when source has" do | ||||
test "1 pad", do: do_test(1) | ||||
test "2 pads", do: do_test(2) | ||||
test "10 pads", do: do_test(10) | ||||
end | ||||
|
||||
defp do_test(sinks_number) do | ||||
auto_demand_size = 20 | ||||
|
||||
spec = | ||||
Stream.repeatedly(fn -> | ||||
get_child(:source) | ||||
|> via_in(:input, auto_demand_size: auto_demand_size) | ||||
|> child(Debug.Sink) | ||||
end) | ||||
|> Stream.take(sinks_number) | ||||
|> Enum.concat([child(:source, Source)]) | ||||
|
||||
pipeline = Testing.Pipeline.start_link_supervised!(spec: spec) | ||||
|
||||
Process.sleep(1_000) | ||||
|
||||
for _i <- 1..(auto_demand_size + 5) do | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this number? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure, that this line
will be executed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now I think, that it would be good to have auto_demand_size < delayed_demand_loop_counter_limit, to ensure, that counter won't reset after reaching linked code. I will change this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so let’s change the naming or add a comment indicating it’s to exceed the loop counter limit |
||||
Testing.Pipeline.notify_child(pipeline, :source, :request) | ||||
assert_pipeline_notified(pipeline, :source, :response) | ||||
end | ||||
|
||||
Testing.Pipeline.terminate(pipeline) | ||||
end | ||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can assert_start_of_stream on each sink instead