Membrane Core v0.3.0 Membrane.Testing.Pipeline View Source
This Pipeline was created to reduce testing boilerplate and ease communication with it's elements.
It also provides utility for receiving messages when Pipeline
playback state changes
and notifications it receives.
Starting Pipeline
When you want a build Pipeline to test your elements you need three things:
- Pipeline Module
- List of elements
- Links between those elements
When creating pipelines for tests the only essential part is the list of elements.
In most cases during the tests elements are linked in a way that
:output
pad is linked to :input
pad of subsequent element.
So we only need to pass a list of elements and links can be generated automatically.
To start a testing pipeline you need to build Membrane.Testing.Pipeline.Options
struct
and pass to to Membrane.Testing.Pipeline.start_link/2
.
options = %Membrane.Testing.Pipeline.Options {
elements: [
el1: MembraneElement1,
el2: MembraneElement2,
...
]
}
{:ok, pipeline} = Membrane.Testing.Pipeline.start_link(options)
See Membrane.Testing.Pipeline.Options
for available options.
Links are generated by populate_links/1
.
Receiving notifications about callbacks invocation
In some cases, you want to get a notification when Pipeline
reaches a certain state.
You can achieve that by monitoring pipeline callbacks.
options = %Membrane.Testing.Pipeline.Options {
monitored_callbacks: [:handle_prepared_to_playing],
test_process: pid
...
}
First, you need to configure which callbacks are to be monitored by putting their names
into monitored_callbacks
field of Options
struct. Check Membrane.Testing.Pipeline.Options.pipeline_callback/0
for list of available callback names.
You also need to pass a PID
of the process that will receive messages.
import Membrane.Testing.Pipeline.Assertions
assert_receive_message :handle_prepared_to_playing
Then it is a matter of waiting for the right message to come.
You can do that easily by using Membrane.Testing.Pipeline.Assertions.assert_receive_message/3
.
Messaging children
You can send messages to children using their names specified in the elements list.
Please check message_child/3
for more details.
Link to this section Summary
Functions
Sends message to a child by Element name
Changes playback state of pipeline to :playing
Links subsequent elements using default pads (linking :input
to :output
of previous element)
Changes playback state to :prepared
Starts the pipeline Membrane.Testing.Pipeline
without linking it
to the current process
Starts the pipeline Membrane.Testing.Pipeline
and links it to the current process
Changes playback state to :stopped
Changes pipeline's playback state to :stopped
and terminates its process
Link to this section Functions
message_child(pipeline, child, message)
View Source
message_child(pid(), Membrane.Element.name_t(), any()) :: :ok
message_child(pid(), Membrane.Element.name_t(), any()) :: :ok
Sends message to a child by Element name.
Examples
Knowing that pipeline
has child named sink
, message can be sent as follows:
message_child(pipeline, :sink, {:message, "to handle"})
play(pipeline)
View Source
play(pid()) :: :ok
play(pid()) :: :ok
Changes playback state of pipeline to :playing
A proxy for Membrane.Pipeline.play/1
populate_links(elements)
View Source
populate_links(elements :: Membrane.Pipeline.Spec.children_spec_t()) ::
Membrane.Pipeline.Spec.links_spec_t()
populate_links(elements :: Membrane.Pipeline.Spec.children_spec_t()) :: Membrane.Pipeline.Spec.links_spec_t()
Links subsequent elements using default pads (linking :input
to :output
of previous element).
Examples
iex> Pipeline.populate_links([el1: MembraneElement1, el2: MembraneElement2])
%{{:el1, :output} => {:el2, :input}}
prepare(pipeline)
View Source
prepare(pid()) :: :ok
prepare(pid()) :: :ok
Changes playback state to :prepared
.
A proxy for Membrane.Pipeline.prepare/1
start(pipeline_options \\ nil, process_options \\ [])
View Source
start(
pipeline_options :: Membrane.Pipeline.pipeline_options_t(),
process_options :: GenServer.options()
) :: GenServer.on_start()
start( pipeline_options :: Membrane.Pipeline.pipeline_options_t(), process_options :: GenServer.options() ) :: GenServer.on_start()
Starts the pipeline Membrane.Testing.Pipeline
without linking it
to the current process.
A proxy for Membrane.Pipeline.start/3
start_link(pipeline_options \\ nil, process_options \\ [])
View Source
start_link(
pipeline_options :: Membrane.Pipeline.pipeline_options_t(),
process_options :: GenServer.options()
) :: GenServer.on_start()
start_link( pipeline_options :: Membrane.Pipeline.pipeline_options_t(), process_options :: GenServer.options() ) :: GenServer.on_start()
Starts the pipeline Membrane.Testing.Pipeline
and links it to the current process.
A proxy for Membrane.Pipeline.start_link/3
stop(pid)
View Source
stop(pid()) :: :ok
stop(pid()) :: :ok
Changes playback state to :stopped
.
A proxy for Membrane.Pipeline.stop/1
stop_and_terminate(pipeline)
View Source
stop_and_terminate(pid()) :: :ok
stop_and_terminate(pid()) :: :ok
Changes pipeline's playback state to :stopped
and terminates its process.
A proxy for Membrane.Pipeline.stop_and_terminate/1