Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write function to get child pid in tests #497

Merged
merged 15 commits into from
Jan 2, 2023
Merged

Write function to get child pid in tests #497

merged 15 commits into from
Jan 2, 2023

Conversation

FelonEkonom
Copy link
Member

@FelonEkonom FelonEkonom commented Dec 16, 2022

child_ref = Child.ref(child_name, opts)

try do
case :sys.get_state(parent_pid) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is meant for debugging purposes and relies on the core internals. Instead, do a normal call to the testing pipeline and make it take the PID from the context.

lib/membrane/testing/pipeline.ex Show resolved Hide resolved
lib/membrane/testing/pipeline.ex Outdated Show resolved Hide resolved
lib/membrane/core/element.ex Show resolved Hide resolved
lib/membrane/testing/pipeline.ex Show resolved Hide resolved
lib/membrane/testing/pipeline.ex Outdated Show resolved Hide resolved
lib/membrane/testing/pipeline.ex Outdated Show resolved Hide resolved
lib/membrane/testing/utils.ex Outdated Show resolved Hide resolved
Comment on lines 270 to 272
try do
GenServer.call(parent_pid, msg)
catch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Message.call instead, it handles the case when the process is not alive

Comment on lines 21 to 28
msg = Message.new(:get_child_pid, child_ref)

try do
GenServer.call(parent_pid, msg)
catch
:exit, {:noproc, {GenServer, :call, [^parent_pid, ^msg | _tail]}} ->
{:error, :parent_not_alive}
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Message.call

"""
@spec get_child_pid(pid(), Child.ref_t()) ::
{:ok, pid()} | {:error, :parent_not_alive | :child_not_found}
def get_child_pid(parent_pid, child_ref) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was to be moved to Membrane.Testing.Pipeline

@@ -0,0 +1,104 @@
defmodule Membrane.Testing.GetChildPidTest do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now this can be moved to testing pipeline tests

If second argument is a child reference, function gets pid of this child
from pipeline.

Id second argument is a path of child references, function gets pid of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Id second argument is a path of child references, function gets pid of
If second argument is a path of child references, function gets pid of

lib/membrane/testing/pipeline.ex Outdated Show resolved Hide resolved
@FelonEkonom FelonEkonom merged commit f5a4cb1 into master Jan 2, 2023
@FelonEkonom FelonEkonom deleted the get-child-pid branch January 2, 2023 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants