-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix the problem with the pipeline crashing when the element with output pads was put on the different node than the toilet was put * Add Membrane.Core.Element.Toilet.DistributedCounter - an abstraction put above the implementation of atomic counter * Add an integration test to check the behavior of the pipeline with elements distributed among nodes
- Loading branch information
Showing
11 changed files
with
305 additions
and
26 deletions.
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,49 @@ | ||
defmodule Membrane.Core.Element.ToiletTest do | ||
use ExUnit.Case | ||
alias Membrane.Core.Element.Toilet | ||
|
||
setup do | ||
[responsible_process: spawn(fn -> nil end)] | ||
end | ||
|
||
test "if toilet is implemented as :atomics for elements put on the same node", context do | ||
toilet = Toilet.new(100, :buffers, context.responsible_process, 1) | ||
|
||
{_module, {_pid, atomic_ref}, _capacity, _responsible_process_pid, _throttling_factor, | ||
_unrinsed_buffers} = toilet | ||
|
||
Toilet.fill(toilet, 10) | ||
assert :atomics.get(atomic_ref, 1) == 10 | ||
Toilet.drain(toilet, 10) | ||
assert :atomics.get(atomic_ref, 1) == 0 | ||
end | ||
|
||
test "if the receiving element uses toilet with :atomics and the sending element with a interprocess message, when the toilet is distributed", | ||
context do | ||
toilet = Toilet.new(100, :buffers, context.responsible_process, 1) | ||
|
||
{_module, {counter_pid, atomic_ref}, _capacity, _responsible_process_pid, _throttling_factor, | ||
_unrinsed_buffers} = toilet | ||
|
||
Toilet.fill(toilet, 10) | ||
assert GenServer.call(counter_pid, {:add_get, atomic_ref, 0}) == 10 | ||
assert :atomics.get(atomic_ref, 1) == 10 | ||
Toilet.drain(toilet, 10) | ||
assert GenServer.call(counter_pid, {:add_get, atomic_ref, 0}) == 0 | ||
assert :atomics.get(atomic_ref, 1) == 0 | ||
end | ||
|
||
test "if throttling mechanism works properly", context do | ||
toilet = Toilet.new(100, :buffers, context.responsible_process, 10) | ||
{:ok, toilet} = Toilet.fill(toilet, 10) | ||
assert {_module, _counter, _capacity, _pid, _throttling_factor, 0} = toilet | ||
{:ok, toilet} = Toilet.fill(toilet, 5) | ||
assert {_module, _counter, _capacity, _pid, _throttling_factor, 5} = toilet | ||
{:ok, toilet} = Toilet.fill(toilet, 80) | ||
assert {_module, _counter, _capacity, _pid, _throttling_factor, 0} = toilet | ||
{:ok, toilet} = Toilet.fill(toilet, 9) | ||
assert {_module, _counter, _capacity, _pid, _throttling_factor, 9} = toilet | ||
{:overflow, toilet} = Toilet.fill(toilet, 11) | ||
assert {_module, _counter, _capacity, _pid, _throttling_factor, 0} = toilet | ||
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
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,62 @@ | ||
defmodule Membrane.Integration.DistributedPipelineTest do | ||
use ExUnit.Case | ||
import Membrane.ParentSpec | ||
import Membrane.Testing.Assertions | ||
alias Membrane.ParentSpec | ||
|
||
alias Membrane.Support.Distributed.{Sink, Source} | ||
|
||
setup do | ||
hostname = start_nodes() | ||
on_exit(fn -> kill_node(hostname) end) | ||
end | ||
|
||
test "if distributed pipeline works properly" do | ||
{:ok, pid} = Membrane.Testing.Pipeline.start([]) | ||
|
||
assert_pipeline_playback_changed(pid, _, :playing) | ||
|
||
Membrane.Testing.Pipeline.execute_actions(pid, playback: :stopped) | ||
|
||
assert_pipeline_playback_changed(pid, _, :stopped) | ||
|
||
Membrane.Testing.Pipeline.execute_actions(pid, | ||
spec: %ParentSpec{ | ||
children: [ | ||
source: %Source{output: [1, 2, 3, 4, 5]} | ||
], | ||
node: :"[email protected]" | ||
} | ||
) | ||
|
||
Membrane.Testing.Pipeline.execute_actions(pid, | ||
spec: %ParentSpec{ | ||
children: [ | ||
sink: Sink | ||
], | ||
links: [ | ||
link(:source) | ||
|> via_in(:input, toilet_capacity: 100, throttling_factor: 50) | ||
|> to(:sink) | ||
], | ||
node: :"[email protected]" | ||
} | ||
) | ||
|
||
Membrane.Testing.Pipeline.execute_actions(pid, playback: :playing) | ||
assert_pipeline_playback_changed(pid, _, :playing) | ||
assert_end_of_stream(pid, :sink) | ||
end | ||
|
||
defp start_nodes() do | ||
System.cmd("epmd", ["-daemon"]) | ||
{:ok, _pid} = Node.start(:"[email protected]", :longnames) | ||
{:ok, _pid, hostname} = :peer.start(%{host: ~c"127.0.0.1", name: :second}) | ||
:rpc.block_call(hostname, :code, :add_paths, [:code.get_path()]) | ||
hostname | ||
end | ||
|
||
defp kill_node(node) do | ||
:rpc.call(node, :init, :stop, []) | ||
end | ||
end |
Oops, something went wrong.