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.

play(pid) deprecated

Changes playback state of pipeline to :playing.

prepare(pid) deprecated

Changes playback state to :prepared.

stop(pid) deprecated

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

Link to this type

custom_pipeline_keyword_list_t()

View Source
@type custom_pipeline_keyword_list_t() :: [
  module: module(),
  custom_args: Membrane.Pipeline.pipeline_options_t(),
  test_process: pid()
]
Link to this type

default_pipeline_keyword_list_t()

View Source
@type default_pipeline_keyword_list_t() :: [
  module: :default,
  children: Membrane.ParentSpec.children_spec_t(),
  links: Membrane.ParentSpec.links_spec_t(),
  test_process: pid()
]
Link to this type

pipeline_keyword_list_t()

View Source
@type pipeline_keyword_list_t() ::
  default_pipeline_keyword_list_t() | custom_pipeline_keyword_list_t()

Link to this section Functions

Link to this function

execute_actions(pipeline, actions)

View Source
@spec execute_actions(pid(), Keyword.t()) :: :ok

Executes specified actions in the pipeline.

The actions are returned from the handle_other callback.

Link to this function

message_child(pipeline, child, message)

View Source
@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"})
This function is deprecated. use pipeline's :playback action instead.
@spec play(pid()) :: :ok

Changes playback state of pipeline to :playing.

This function is deprecated. use pipeline's :playback action instead.
@spec prepare(pid()) :: :ok

Changes playback state to :prepared.

Link to this function

start(pipeline_options, process_options \\ [])

View Source
Link to this function

start_link(pipeline_options, process_options \\ [])

View Source
This function is deprecated. use pipeline's :playback action instead.
@spec stop(pid()) :: :ok

Changes playback state to :stopped.

Link to this function

stop_and_terminate(pipeline, opts \\ [])

View Source
This function is deprecated. use terminate/2 instead.
@spec stop_and_terminate(pid(), Keyword.t()) :: :ok

Changes pipeline's playback state to :stopped and terminates its process.

Link to this function

terminate(pipeline, opts \\ [])

View Source
@spec terminate(pid(), Keyword.t()) :: :ok

Changes pipeline's playback state to :stopped and terminates its process.