Skip to content

Commit

Permalink
Merge pull request #422 from membraneframework/bugfix/elements-keywor…
Browse files Browse the repository at this point in the history
…d-in-testing-pipeline-options

Revoke `:elements` key in Membrane.Testing.Pipeline.Options struct
  • Loading branch information
varsill authored Apr 22, 2022
2 parents 1f1938c + 259d460 commit 378774d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
7 changes: 2 additions & 5 deletions lib/membrane/parent_spec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -466,18 +466,15 @@ defmodule Membrane.ParentSpec do

@doc """
Links subsequent children using default pads (linking `:input` to `:output` of
previous element).
previous element). The list of children must consist at least of 2 elements.
## Example
Membrane.ParentSpec.link_linear([el1: MembraneElement1, el2: MembraneElement2])
"""
@spec link_linear(children :: [child_spec_t()]) :: links_spec_t()
def link_linear([]) do
[]
end

def link_linear(children) when is_list(children) do
def link_linear(children) when is_list(children) and length(children) > 1 do
[{first_child_name, first_child_spec} | other_children] = children

links =
Expand Down
45 changes: 33 additions & 12 deletions lib/membrane/testing/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ defmodule Membrane.Testing.Pipeline do
alias Membrane.ParentSpec
alias Membrane.Testing.Notification

require Membrane.Logger

defmodule Options do
@moduledoc """
@deprecated
Expand All @@ -102,18 +104,18 @@ defmodule Membrane.Testing.Pipeline do
- `:test_process` - `pid` of process that shall receive messages from testing pipeline, e.g. when pipeline's playback state changes.
This allows using `Membrane.Testing.Assertions`
- `:children` - a list of element specs. Allows to create a simple pipeline without defining a module for it.
- `:elements` - a list of element specs. Allows to create a simple pipeline without defining a module for it.
- `:links` - a list describing the links between children. If ommited (or set to `nil`), they will be populated automatically
based on the children order using default pad names.
- `:module` - pipeline module with custom callbacks - useful if a simple list of children is not enough.
- `:custom_args`- arguments for the module's `handle_init` callback.
"""

defstruct [:children, :links, :test_process, :module, :custom_args]
defstruct [:elements, :links, :test_process, :module, :custom_args]

@type t :: %__MODULE__{
test_process: pid() | nil,
children: ParentSpec.children_spec_t() | nil,
elements: ParentSpec.children_spec_t() | nil,
links: ParentSpec.links_spec_t() | nil,
module: module() | nil,
custom_args: Pipeline.pipeline_options_t() | nil
Expand Down Expand Up @@ -164,7 +166,7 @@ defmodule Membrane.Testing.Pipeline do
def start_link(pipeline_options, process_options \\ [])

def start_link(pipeline_options, process_options) when is_struct(pipeline_options, Options) do
IO.warn(
Membrane.Logger.warn(
"Please pass options to Membrane.Testing.Pipeline.start_link/2 as keyword list, instead of using Membrane.Testing.Options"
)

Expand All @@ -181,7 +183,7 @@ defmodule Membrane.Testing.Pipeline do
def start(pipeline_options, process_options \\ [])

def start(pipeline_options, process_options) when is_struct(pipeline_options, Options) do
IO.warn(
Membrane.Logger.warn(
"Please pass options to Membrane.Testing.Pipeline.start/2 as keyword list, instead of using Membrane.Testing.Options"
)

Expand Down Expand Up @@ -219,7 +221,7 @@ defmodule Membrane.Testing.Pipeline do
end
end

defp do_start(_type, %Options{children: nil, module: nil}, _process_options) do
defp do_start(_type, %Options{elements: nil, module: nil}, _process_options) do
raise """
You provided no information about pipeline contents. Please provide either:
Expand All @@ -230,7 +232,7 @@ defmodule Membrane.Testing.Pipeline do
"""
end

defp do_start(_type, %Options{children: children, module: module}, _process_options)
defp do_start(_type, %Options{elements: children, module: module}, _process_options)
when is_atom(module) and module != nil and children != nil do
raise """
Expand Down Expand Up @@ -274,18 +276,37 @@ defmodule Membrane.Testing.Pipeline do

@impl true
def handle_init(%Options{links: nil, module: nil} = options) do
new_links = ParentSpec.link_linear(options.children)
do_handle_init_for_default_implementation(%Options{options | links: new_links})
{links, children} =
if length(options.elements) <= 1 do
{[], options.elements}
else
{ParentSpec.link_linear(options.elements), []}
end

options_map = %{children: children, links: links, test_process: options.test_process}
do_handle_init_for_default_implementation(options_map)
end

@impl true
def handle_init(%Options{module: nil} = options) do
do_handle_init_for_default_implementation(options)
options_map = %{
children: options.elements,
links: options.links,
test_process: options.test_process
}

do_handle_init_for_default_implementation(options_map)
end

@impl true
def handle_init(%Options{links: nil, children: nil} = options) do
do_handle_init_with_custom_module(options)
def handle_init(%Options{links: nil, elements: nil} = options) do
options_map = %{
test_process: options.test_process,
module: options.module,
custom_args: options.custom_args
}

do_handle_init_with_custom_module(options_map)
end

@impl true
Expand Down

0 comments on commit 378774d

Please sign in to comment.