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

make most tests run async #576

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions test/membrane/clock_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
defmodule Membrane.ClockTest.Sync do
use ExUnit.Case, async: false

@module Membrane.Clock

@initial_ratio Ratio.new(1)

test "should send proper ratio when default time provider is used" do
ratio_error = 0.3
{:ok, clock} = @module.start_link()
@module.subscribe(clock)
assert_receive {:membrane_clock_ratio, ^clock, @initial_ratio}
send(clock, {:membrane_clock_update, 100})
Process.send_after(clock, {:membrane_clock_update, 100}, 50)
Process.send_after(clock, {:membrane_clock_update, random_time()}, 100)
assert_receive {:membrane_clock_ratio, ^clock, ratio}
assert_in_delta Ratio.to_float(ratio), 100 / 50, ratio_error
assert_receive {:membrane_clock_ratio, ^clock, ratio}
assert_in_delta Ratio.to_float(ratio), 100 / 50, ratio_error
end

defp random_time, do: :rand.uniform(10_000)
end
Copy link
Member

Choose a reason for hiding this comment

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

IMO it is not nice to have modules Membrane.ClockTest.Sync and Membrane.ClockTest on the same level in file named clock_test.exs


defmodule Membrane.ClockTest do
use ExUnit.Case
use ExUnit.Case, async: true

@module Membrane.Clock

Expand Down Expand Up @@ -43,20 +67,6 @@ defmodule Membrane.ClockTest do
assert_receive {:membrane_clock_ratio, ^clock, ^ratio}
end

test "should send proper ratio when default time provider is used" do
ratio_error = 0.3
{:ok, clock} = @module.start_link()
@module.subscribe(clock)
assert_receive {:membrane_clock_ratio, ^clock, @initial_ratio}
send(clock, {:membrane_clock_update, 100})
Process.send_after(clock, {:membrane_clock_update, 100}, 50)
Process.send_after(clock, {:membrane_clock_update, random_time()}, 100)
assert_receive {:membrane_clock_ratio, ^clock, ratio}
assert_in_delta Ratio.to_float(ratio), 100 / 50, ratio_error
assert_receive {:membrane_clock_ratio, ^clock, ratio}
assert_in_delta Ratio.to_float(ratio), 100 / 50, ratio_error
end

describe "should send current ratio once a new subscriber connects" do
test "when no updates have been sent" do
{:ok, clock} = @module.start_link()
Expand Down
4 changes: 1 addition & 3 deletions test/membrane/core/element/atomic_demand_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Core.Element.AtomicDemandTest do
use ExUnit.Case
use ExUnit.Case, async: true

alias Membrane.Core.Element.AtomicDemand
alias Membrane.Core.SubprocessSupervisor
Expand Down Expand Up @@ -126,8 +126,6 @@ defmodule Membrane.Core.Element.AtomicDemandTest do
end

defp setup_another_node() do
_cmd_result = System.cmd("epmd", ["-daemon"])
_start_result = Node.start(:"[email protected]", :longnames)
{:ok, _pid, another_node} = :peer.start(%{host: ~c"127.0.0.1", name: :another_node})
:rpc.block_call(another_node, :code, :add_paths, [:code.get_path()])

Expand Down
2 changes: 1 addition & 1 deletion test/membrane/core/element/event_controller_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Core.Element.EventControllerTest do
use ExUnit.Case
use ExUnit.Case, async: true

alias Membrane.Core.Element.{AtomicDemand, EventController, InputQueue, State}
alias Membrane.Core.Events
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/core/element/lifecycle_controller_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Core.Element.LifecycleControllerTest do
use ExUnit.Case
use ExUnit.Case, async: true

alias Membrane.Core.Element.{AtomicDemand, InputQueue, LifecycleController, State}

Expand Down
2 changes: 1 addition & 1 deletion test/membrane/core/parent/structure_parser_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Core.Parent.SpecificationParserTest do
use ExUnit.Case
use ExUnit.Case, async: true

alias Membrane.Core.Parent.{Link, SpecificationParser}
alias Membrane.Core.Parent.Link.Endpoint
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/core/pipeline_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Core.PipelineTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.Testing.Assertions
import Membrane.ChildrenSpec
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/integration/child_crash_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Integration.ChildCrashTest do
use ExUnit.Case, async: false
use ExUnit.Case, async: true

import Membrane.ChildrenSpec
import Membrane.Testing.Assertions
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/integration/child_pad_removed_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Integration.ChildPadRemovedTest do
use ExUnit.Case, async: false
use ExUnit.Case, async: true

alias Membrane.Testing

Expand Down
2 changes: 1 addition & 1 deletion test/membrane/integration/child_removal_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Membrane.Integration.ChildRemovalTest do
use Bunch
use ExUnit.Case, async: false
use ExUnit.Case, async: true

import Membrane.Testing.Assertions

Expand Down
2 changes: 1 addition & 1 deletion test/membrane/integration/child_spawn_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Membrane.Integration.ChildSpawnTest do
use Bunch
use ExUnit.Case, async: false
use ExUnit.Case, async: true

import Membrane.ChildrenSpec
import Membrane.Testing.Assertions
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/integration/debug_elements_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Integration.DebugElementsTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.ChildrenSpec
import Membrane.Testing.Assertions
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/integration/defer_setup_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Integration.DeferSetupTest do
use ExUnit.Case, async: false
use ExUnit.Case, async: true

import Membrane.ChildrenSpec
import Membrane.Testing.Assertions
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/integration/demands_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Membrane.Integration.DemandsTest do
use Bunch
use ExUnit.Case, async: false
use ExUnit.Case, async: true

import ExUnit.Assertions
import Membrane.ChildrenSpec
Expand Down
4 changes: 1 addition & 3 deletions test/membrane/integration/distributed_pipeline_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Integration.DistributedPipelineTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.Testing.Assertions

Expand Down Expand Up @@ -39,8 +39,6 @@ defmodule Membrane.Integration.DistributedPipelineTest do
end

defp start_another_node() do
System.cmd("epmd", ["-daemon"])
_start_result = Node.start(:"[email protected]", :longnames)
{:ok, _pid, hostname} = :peer.start(%{host: ~c"127.0.0.1", name: :second})
:rpc.block_call(hostname, :code, :add_paths, [:code.get_path()])
hostname
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Integration.EffectiveFlowControlResolutionTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.ChildrenSpec
import Membrane.Testing.Assertions
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/integration/linking_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Integration.LinkingTest do
use ExUnit.Case, async?: true
use ExUnit.Case, async: true

import Membrane.Testing.Assertions
import Membrane.ChildrenSpec
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/integration/links_validation_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.LinksValidationTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.ChildrenSpec

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.FailWhenNoStreamFormatAreSent do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.Testing.Assertions
import Membrane.ChildrenSpec
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/integration/stream_format_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.StreamFormatTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.ChildrenSpec
import Membrane.Testing.Assertions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule PipelineSynchronousCallTest do
use ExUnit.Case, async: false
use ExUnit.Case, async: true

import Membrane.Testing.Assertions

Expand Down
2 changes: 1 addition & 1 deletion test/membrane/log_metadata_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.LogMetadataTest do
use ExUnit.Case, async: false
use ExUnit.Case, async: true

import Membrane.Testing.Assertions

Expand Down
2 changes: 1 addition & 1 deletion test/membrane/pipeline_supervisor_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.PipelineSupervisorTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.ChildrenSpec
import Membrane.Testing.Assertions
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/remote_controlled/pipeline_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.RCPipelineTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.ChildrenSpec

Expand Down
2 changes: 1 addition & 1 deletion test/membrane/sync_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Membrane.SyncTest do
use Bunch
use ExUnit.Case
use ExUnit.Case, async: true

@module Membrane.Sync

Expand Down
2 changes: 1 addition & 1 deletion test/membrane/testing/dynamic_source_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Testing.DynamicSourceTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.ChildrenSpec
import Membrane.Testing.Assertions
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/testing/endpoint_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Testing.EndpointTest do
use ExUnit.Case
use ExUnit.Case, async: true

alias Membrane.Buffer
alias Membrane.Testing.{Endpoint, Notification}
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/testing/mock_resource_guard_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Testing.MockResourceGuardTest do
use ExUnit.Case
use ExUnit.Case, async: true

doctest Membrane.Testing.MockResourceGuard
end
2 changes: 1 addition & 1 deletion test/membrane/testing/pipeline_assertions_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Testing.PipelineAssertionsTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.Testing.Assertions

Expand Down
2 changes: 1 addition & 1 deletion test/membrane/testing/pipeline_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Testing.PipelineTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.ChildrenSpec
import Membrane.Testing.Assertions
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/testing/sink_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Testing.SinkTest do
use ExUnit.Case
use ExUnit.Case, async: true

alias Membrane.Testing.Notification
alias Membrane.Testing.Sink
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/testing/source_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.Testing.SourceTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.ChildrenSpec
import Membrane.Testing.Assertions
Expand Down
2 changes: 1 addition & 1 deletion test/membrane/utility_supervisor_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Membrane.UtilitySupervisorTest do
use ExUnit.Case
use ExUnit.Case, async: true

import Membrane.ChildrenSpec
import Membrane.Testing.Assertions
Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# needed for testing distribution features
System.cmd("epmd", ["-daemon"])
Node.start(:"[email protected]", :longnames)

ExUnit.configure(formatters: [ExUnit.CLIFormatter, JUnitFormatter])
ExUnit.start(exclude: [:long_running], capture_log: true, assert_receive_timeout: 500)