Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into update-pipeline-ter…
Browse files Browse the repository at this point in the history
…minate
  • Loading branch information
FelonEkonom committed Feb 14, 2023
2 parents b0055fc + ca082cb commit c44f4b9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/membrane/core/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ defmodule Membrane.Core.Pipeline do
def handle_call(message, from, state) do
context = &CallbackContext.from_state(&1, from: from)

CallbackHandler.exec_and_handle_callback(
:handle_call,
Membrane.Core.Pipeline.ActionHandler,
%{context: context},
[message],
state
)
state =
CallbackHandler.exec_and_handle_callback(
:handle_call,
Membrane.Core.Pipeline.ActionHandler,
%{context: context},
[message],
state
)

{:noreply, state}
end
Expand Down
34 changes: 34 additions & 0 deletions test/membrane/integration/synchronous_pipeline_call_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule PipelineSynchronousCallTest do
use ExUnit.Case, async: false

import Membrane.Testing.Assertions

alias Membrane.Pipeline

@msg "Some message"
Expand Down Expand Up @@ -38,12 +40,44 @@ defmodule PipelineSynchronousCallTest do

reply = Pipeline.call(pid, {:postponed_reply, @msg})
assert reply == @msg

Pipeline.terminate(pid)
end

test "Pipeline should be able to reply to a call with :reply action" do
pid = Membrane.Testing.Pipeline.start_link_supervised!(module: TestPipeline)

reply = Pipeline.call(pid, {:instant_reply, @msg})
assert reply == @msg

Pipeline.terminate(pid)
end

defmodule PipelineSpawningChildrenOnCall do
use Membrane.Pipeline

@impl true
def handle_init(_ctx, _options) do
{[], %{}}
end

@impl true
def handle_call(:spawn_children, _ctx, state) do
spec =
child(:source, %Membrane.Testing.Source{output: [1, 2, 3]})
|> child(:sink, Membrane.Testing.Sink)

{[spec: spec, reply: nil], state}
end
end

test "Pipeline should be able to perform actions before replying on handle_call" do
{:ok, _supervisor, pipeline_pid} =
Membrane.Testing.Pipeline.start(module: PipelineSpawningChildrenOnCall)

Pipeline.call(pipeline_pid, :spawn_children)
assert_end_of_stream(pipeline_pid, :sink)

Pipeline.terminate(pipeline_pid)
end
end

0 comments on commit c44f4b9

Please sign in to comment.