View Source Membrane.Testing.Pipeline (Membrane Core v0.11.3)
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 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_supervised!/1
.
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:
links = [
child(:el1, MembraneElement1) |>
child(:el2, MembraneElement2)
...
]
options = [
module: :default # :default is the default value for this parameter, so you do not need to pass it here
structure: links
]
pipeline = Membrane.Testing.Pipeline.start_link_supervised!(options)
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
]
pipeline = Membrane.Testing.Pipeline.start_link_supervised!(options)
See Membrane.Testing.Pipeline.options/0
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: import Membrane.ChildrenSpec children = [
child(source, %Membrane.Testing.Source{} ) |>
child(:tested_element, TestedElement) |>
child(sink, %Membrane.Testing.Sink{})
] {:ok, pipeline} = Membrane.Testing.Pipeline.start_link(structure: links)
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
Returns child specification for spawning under a supervisor
Executes specified actions in the pipeline.
Sends message to a child by Element name.
Starts the pipeline under the ExUnit test supervisor and links it to the current process.
Starts the pipeline under the ExUnit test supervisor.
Changes pipeline's playback to :stopped
and terminates its process.
Link to this section Types
@type options() :: [ module: :default, structure: [Membrane.ChildrenSpec.structure_builder_t()], test_process: pid(), name: Membrane.Pipeline.name() ] | [ module: module(), custom_args: Membrane.Pipeline.pipeline_options(), test_process: pid(), name: Membrane.Pipeline.name() ]
Link to this section Functions
@spec child_spec(options()) :: Supervisor.child_spec()
Returns child specification for spawning under a supervisor
Executes specified actions in the pipeline.
The actions are returned from the handle_info
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 start(options()) :: Membrane.Pipeline.on_start()
@spec start_link(options()) :: Membrane.Pipeline.on_start()
@spec start_link_supervised(options()) :: Membrane.Pipeline.on_start()
Starts the pipeline under the ExUnit test supervisor and links it to the current process.
Can be used only in tests.
@spec start_supervised(options()) :: Membrane.Pipeline.on_start()
Starts the pipeline under the ExUnit test supervisor.
Can be used only in tests.
Changes pipeline's playback to :stopped
and terminates its process.