Membrane Core v0.2.2 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

Links subsequent elements using default pads (linking :input to :output of previous element)

Starts the Testing Pipeline and links it to the current process

Link to this section Functions

Link to this function

message_child(pipeline, child, message) View Source
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"})

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}}
Link to this function

start_link(options, process_options \\ []) View Source
start_link(
  pipeline_options :: Membrane.Testing.Pipeline.Options.t(),
  process_options :: GenServer.options()
) :: GenServer.on_start()

Starts the Testing Pipeline and links it to the current process.

Proxy for Membrane.Pipeline.start_link/3.