View Source Membrane.Testing.Pipeline (Membrane Core v0.10.2)
This Pipeline was created to reduce testing boilerplate and ease communication with its children. It also provides a utility for informing testing process about playback state changes and received notifications.
When you want a build Pipeline to test your children you need three things:
- Pipeline Module
- List of children
- Links between those children
To start a testing pipeline you need to build
a keyword list representing the options used to determine the pipeline's behaviour and then
pass that options list to the Membrane.Testing.Pipeline.start_link/2
.
The testing pipeline can be started in one of two modes - either with its :default
behaviour, or by
injecting a custom module behaviour. The usage of a :default
pipeline implementation is presented below:
children = [
el1: MembraneElement1,
el2: MembraneElement2,
...
]
options = [
module: :default # :default is the default value for this parameter, so you do not need to pass it here
links: Membrane.ParentSpec.link_linear(children)
]
{:ok, pipeline} = Membrane.Testing.Pipeline.start_link(options)
Note, that we have used Membrane.Testing.ParentSpec.link_linear/1
function, that creates the list of links
for the given list of children, linking them in linear manner (that means - children are linked in a way that
:output
pad of a given child is linked to :input
pad of subsequent child). That is the case
which is often used while creating testing pipelines. Be aware, that Membrane.Testing.ParentSpec.link_linear/1
creates also a children specification itself, which means, that you cannot pass that children specification
as another option's argument (adding children: children
option would lead to a duplication of children specifications).
If you need to link children in a different manner, you can of course do it by passing an appropriate list
of links as a :links
option, just as you would do with a regular pipeline.
You can also pass your custom pipeline's module as a :module
option of
the options list. Every callback of the module
will be executed before the callbacks of Testing.Pipeline.
Passed module has to return a proper spec. There should be no children
nor links specified in options passed to test pipeline as that would
result in a failure.
options = [
module: Your.Module
]
{:ok, pipeline} = Membrane.Testing.Pipeline.start_link(options)
See Membrane.Testing.Pipeline.pipeline_keyword_list_t()
for available options.
assertions
Assertions
This pipeline is designed to work with Membrane.Testing.Assertions
. Check
them out or see example below for more details.
messaging-children
Messaging children
You can send messages to children using their names specified in the children
list. Please check message_child/3
for more details.
example-usage
Example usage
Firstly, we can start the pipeline providing its options as a keyword list:
children = [
source: %Membrane.Testing.Source{},
tested_element: TestedElement,
sink: %Membrane.Testing.Sink{}
]
{:ok, pipeline} = Membrane.Testing.Pipeline.start_link(links: Membrane.ParentSpec.link_linear(children))
We can now wait till the end of the stream reaches the sink element (don't forget
to import Membrane.Testing.Assertions
):
assert_end_of_stream(pipeline, :sink)
We can also assert that the Membrane.Testing.Sink
processed a specific
buffer:
assert_sink_buffer(pipeline, :sink, %Membrane.Buffer{payload: 1})
Link to this section Summary
Functions
Executes specified actions in the pipeline.
Sends message to a child by Element name.
Changes playback state of pipeline to :playing
.
Changes playback state to :prepared
.
Changes playback state to :stopped
.
Changes pipeline's playback state to :stopped
and terminates its process.
Changes pipeline's playback state to :stopped
and terminates its process.
Link to this section Types
@type custom_pipeline_keyword_list_t() :: [ module: module(), custom_args: Membrane.Pipeline.pipeline_options_t(), test_process: pid() ]
@type default_pipeline_keyword_list_t() :: [ module: :default, children: Membrane.ParentSpec.children_spec_t(), links: Membrane.ParentSpec.links_spec_t(), test_process: pid() ]
@type pipeline_keyword_list_t() :: default_pipeline_keyword_list_t() | custom_pipeline_keyword_list_t()
Link to this section Functions
Executes specified actions in the pipeline.
The actions are returned from the handle_other
callback.
@spec message_child(pid(), Membrane.Element.name_t(), any()) :: :ok
Sends message to a child by Element name.
example
Example
Knowing that pipeline
has child named sink
, message can be sent as follows:
message_child(pipeline, :sink, {:message, "to handle"})
@spec play(pid()) :: :ok
Changes playback state of pipeline to :playing
.
@spec prepare(pid()) :: :ok
Changes playback state to :prepared
.
@spec start( Membrane.Testing.Pipeline.Options.t() | pipeline_keyword_list_t(), GenServer.options() ) :: GenServer.on_start()
@spec start_link( Membrane.Testing.Pipeline.Options.t() | pipeline_keyword_list_t(), GenServer.options() ) :: GenServer.on_start()
@spec stop(pid()) :: :ok
Changes playback state to :stopped
.
Changes pipeline's playback state to :stopped
and terminates its process.
Changes pipeline's playback state to :stopped
and terminates its process.