-
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4a24e93
Membrane.Testing.Pipeline.message_child/3 -> notify_child/3
FelonEkonom 150069c
Write test for delayed demands loop, send at most 1 resume delayed de…
FelonEkonom f4be83d
Set default fields values in Element state
FelonEkonom 430933d
Add line to changelog
FelonEkonom ee7cf48
Rename test
FelonEkonom b40b1e4
Rename function
FelonEkonom d1068aa
Refactor test
FelonEkonom bd5f8f3
Refactor due to CR
FelonEkonom 06ac9c9
Comment due to CR
FelonEkonom a83dd86
Merge remote-tracking branch 'origin/master' into tests-upgrade
FelonEkonom f712328
Refactor comment
FelonEkonom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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 is smaller than delayed_demands_loop_counter_limit to ensure, that counter | ||
# doesn't reset after calling handle_demand caused by reading positive atomic demand value | ||
# during the snaphsot | ||
auto_demand_size = 15 | ||
requests_number = 20 | ||
|
||
spec = | ||
[child(:source, Source)] ++ | ||
for i <- 1..sinks_number do | ||
get_child(:source) | ||
|> via_in(:input, auto_demand_size: auto_demand_size) | ||
|> child({:sink, i}, Debug.Sink) | ||
end | ||
|
||
pipeline = Testing.Pipeline.start_link_supervised!(spec: spec) | ||
|
||
for i <- 1..sinks_number do | ||
assert_start_of_stream(pipeline, {:sink, ^i}) | ||
end | ||
|
||
for _i <- 1..requests_number do | ||
Testing.Pipeline.notify_child(pipeline, :source, :request) | ||
assert_pipeline_notified(pipeline, :source, :response) | ||
end | ||
|
||
Testing.Pipeline.terminate(pipeline) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.