From 20fd09fa6a73c29aa2739cebbe9e3407498b10c5 Mon Sep 17 00:00:00 2001 From: Mateusz Front Date: Wed, 12 Jul 2023 13:25:31 +0200 Subject: [PATCH 1/2] make most tests run async --- test/membrane/clock_test.exs | 40 ++++++++++++------- .../core/element/atomic_demand_test.exs | 4 +- .../core/element/event_controller_test.exs | 2 +- .../element/lifecycle_controller_test.exs | 2 +- .../core/parent/structure_parser_test.exs | 2 +- test/membrane/core/pipeline_test.exs | 2 +- .../membrane/integration/child_crash_test.exs | 2 +- .../integration/child_pad_removed_test.exs | 2 +- .../integration/child_removal_test.exs | 2 +- .../membrane/integration/child_spawn_test.exs | 2 +- .../integration/debug_elements_test.exs | 2 +- .../membrane/integration/defer_setup_test.exs | 2 +- test/membrane/integration/demands_test.exs | 2 +- .../integration/distributed_pipeline_test.exs | 4 +- ...effective_flow_control_resolution_test.exs | 2 +- test/membrane/integration/linking_test.exs | 2 +- .../integration/links_validation_test.exs | 2 +- .../no_stream_format_crash_test.exs | 2 +- .../integration/stream_format_test.exs | 2 +- .../synchronous_pipeline_call_test.exs | 2 +- test/membrane/log_metadata_test.exs | 2 +- test/membrane/pipeline_supervisor_test.exs | 2 +- .../remote_controlled/pipeline_test.exs | 2 +- test/membrane/sync_test.exs | 2 +- test/membrane/testing/dynamic_source_test.exs | 2 +- test/membrane/testing/endpoint_test.exs | 2 +- .../testing/mock_resource_guard_test.exs | 2 +- .../testing/pipeline_assertions_test.exs | 2 +- test/membrane/testing/pipeline_test.exs | 2 +- test/membrane/testing/sink_test.exs | 2 +- test/membrane/testing/source_test.exs | 2 +- test/membrane/utility_supervisor_test.exs | 2 +- test/test_helper.exs | 4 ++ 33 files changed, 60 insertions(+), 50 deletions(-) diff --git a/test/membrane/clock_test.exs b/test/membrane/clock_test.exs index 2ec21c895..12a143cdc 100644 --- a/test/membrane/clock_test.exs +++ b/test/membrane/clock_test.exs @@ -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 + defmodule Membrane.ClockTest do - use ExUnit.Case + use ExUnit.Case, async: true @module Membrane.Clock @@ -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() diff --git a/test/membrane/core/element/atomic_demand_test.exs b/test/membrane/core/element/atomic_demand_test.exs index b6490b219..0cbd513fd 100644 --- a/test/membrane/core/element/atomic_demand_test.exs +++ b/test/membrane/core/element/atomic_demand_test.exs @@ -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 @@ -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(:"my_node@127.0.0.1", :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()]) diff --git a/test/membrane/core/element/event_controller_test.exs b/test/membrane/core/element/event_controller_test.exs index 0a5a73aca..c92dcd4c0 100644 --- a/test/membrane/core/element/event_controller_test.exs +++ b/test/membrane/core/element/event_controller_test.exs @@ -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 diff --git a/test/membrane/core/element/lifecycle_controller_test.exs b/test/membrane/core/element/lifecycle_controller_test.exs index ac6585ae2..32a7d363a 100644 --- a/test/membrane/core/element/lifecycle_controller_test.exs +++ b/test/membrane/core/element/lifecycle_controller_test.exs @@ -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} diff --git a/test/membrane/core/parent/structure_parser_test.exs b/test/membrane/core/parent/structure_parser_test.exs index 18e99a992..7be344970 100644 --- a/test/membrane/core/parent/structure_parser_test.exs +++ b/test/membrane/core/parent/structure_parser_test.exs @@ -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 diff --git a/test/membrane/core/pipeline_test.exs b/test/membrane/core/pipeline_test.exs index 9815dd53c..5ef8f2f7d 100644 --- a/test/membrane/core/pipeline_test.exs +++ b/test/membrane/core/pipeline_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.Core.PipelineTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.Testing.Assertions import Membrane.ChildrenSpec diff --git a/test/membrane/integration/child_crash_test.exs b/test/membrane/integration/child_crash_test.exs index 9118a6903..f90ac6942 100644 --- a/test/membrane/integration/child_crash_test.exs +++ b/test/membrane/integration/child_crash_test.exs @@ -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 diff --git a/test/membrane/integration/child_pad_removed_test.exs b/test/membrane/integration/child_pad_removed_test.exs index c9fd4300f..438383086 100644 --- a/test/membrane/integration/child_pad_removed_test.exs +++ b/test/membrane/integration/child_pad_removed_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.Integration.ChildPadRemovedTest do - use ExUnit.Case, async: false + use ExUnit.Case, async: true alias Membrane.Testing diff --git a/test/membrane/integration/child_removal_test.exs b/test/membrane/integration/child_removal_test.exs index e498905d3..01a4d5cc4 100644 --- a/test/membrane/integration/child_removal_test.exs +++ b/test/membrane/integration/child_removal_test.exs @@ -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 diff --git a/test/membrane/integration/child_spawn_test.exs b/test/membrane/integration/child_spawn_test.exs index 067e0692a..d0ec29f66 100644 --- a/test/membrane/integration/child_spawn_test.exs +++ b/test/membrane/integration/child_spawn_test.exs @@ -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 diff --git a/test/membrane/integration/debug_elements_test.exs b/test/membrane/integration/debug_elements_test.exs index 65c575840..3d0704efa 100644 --- a/test/membrane/integration/debug_elements_test.exs +++ b/test/membrane/integration/debug_elements_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.Integration.DebugElementsTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.ChildrenSpec import Membrane.Testing.Assertions diff --git a/test/membrane/integration/defer_setup_test.exs b/test/membrane/integration/defer_setup_test.exs index d98369d61..75bb82cc6 100644 --- a/test/membrane/integration/defer_setup_test.exs +++ b/test/membrane/integration/defer_setup_test.exs @@ -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 diff --git a/test/membrane/integration/demands_test.exs b/test/membrane/integration/demands_test.exs index f0078d0ab..b6e3ff604 100644 --- a/test/membrane/integration/demands_test.exs +++ b/test/membrane/integration/demands_test.exs @@ -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 diff --git a/test/membrane/integration/distributed_pipeline_test.exs b/test/membrane/integration/distributed_pipeline_test.exs index 4792d8ccd..c17672a8c 100644 --- a/test/membrane/integration/distributed_pipeline_test.exs +++ b/test/membrane/integration/distributed_pipeline_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.Integration.DistributedPipelineTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.Testing.Assertions @@ -39,8 +39,6 @@ defmodule Membrane.Integration.DistributedPipelineTest do end defp start_another_node() do - System.cmd("epmd", ["-daemon"]) - _start_result = Node.start(:"first@127.0.0.1", :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 diff --git a/test/membrane/integration/effective_flow_control_resolution_test.exs b/test/membrane/integration/effective_flow_control_resolution_test.exs index 5c303a949..15a1c142c 100644 --- a/test/membrane/integration/effective_flow_control_resolution_test.exs +++ b/test/membrane/integration/effective_flow_control_resolution_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.Integration.EffectiveFlowControlResolutionTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.ChildrenSpec import Membrane.Testing.Assertions diff --git a/test/membrane/integration/linking_test.exs b/test/membrane/integration/linking_test.exs index a20621121..0a8fca083 100644 --- a/test/membrane/integration/linking_test.exs +++ b/test/membrane/integration/linking_test.exs @@ -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 diff --git a/test/membrane/integration/links_validation_test.exs b/test/membrane/integration/links_validation_test.exs index 84050b118..ff301afdc 100644 --- a/test/membrane/integration/links_validation_test.exs +++ b/test/membrane/integration/links_validation_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.LinksValidationTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.ChildrenSpec diff --git a/test/membrane/integration/no_stream_format_crash_test.exs b/test/membrane/integration/no_stream_format_crash_test.exs index 18a33d455..c6abad1dd 100644 --- a/test/membrane/integration/no_stream_format_crash_test.exs +++ b/test/membrane/integration/no_stream_format_crash_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.FailWhenNoStreamFormatAreSent do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.Testing.Assertions import Membrane.ChildrenSpec diff --git a/test/membrane/integration/stream_format_test.exs b/test/membrane/integration/stream_format_test.exs index 75c4a55fd..1b86c490c 100644 --- a/test/membrane/integration/stream_format_test.exs +++ b/test/membrane/integration/stream_format_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.StreamFormatTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.ChildrenSpec import Membrane.Testing.Assertions diff --git a/test/membrane/integration/synchronous_pipeline_call_test.exs b/test/membrane/integration/synchronous_pipeline_call_test.exs index fe5ff3b4a..f8da96a4c 100644 --- a/test/membrane/integration/synchronous_pipeline_call_test.exs +++ b/test/membrane/integration/synchronous_pipeline_call_test.exs @@ -1,5 +1,5 @@ defmodule PipelineSynchronousCallTest do - use ExUnit.Case, async: false + use ExUnit.Case, async: true import Membrane.Testing.Assertions diff --git a/test/membrane/log_metadata_test.exs b/test/membrane/log_metadata_test.exs index 68a30cfc4..e2386db21 100644 --- a/test/membrane/log_metadata_test.exs +++ b/test/membrane/log_metadata_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.LogMetadataTest do - use ExUnit.Case, async: false + use ExUnit.Case, async: true import Membrane.Testing.Assertions diff --git a/test/membrane/pipeline_supervisor_test.exs b/test/membrane/pipeline_supervisor_test.exs index 9ba264c44..cdaf6605e 100644 --- a/test/membrane/pipeline_supervisor_test.exs +++ b/test/membrane/pipeline_supervisor_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.PipelineSupervisorTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.ChildrenSpec import Membrane.Testing.Assertions diff --git a/test/membrane/remote_controlled/pipeline_test.exs b/test/membrane/remote_controlled/pipeline_test.exs index 02cdfe45c..5a57bbc3d 100644 --- a/test/membrane/remote_controlled/pipeline_test.exs +++ b/test/membrane/remote_controlled/pipeline_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.RCPipelineTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.ChildrenSpec diff --git a/test/membrane/sync_test.exs b/test/membrane/sync_test.exs index d99a4eace..d750046fa 100644 --- a/test/membrane/sync_test.exs +++ b/test/membrane/sync_test.exs @@ -1,6 +1,6 @@ defmodule Membrane.SyncTest do use Bunch - use ExUnit.Case + use ExUnit.Case, async: true @module Membrane.Sync diff --git a/test/membrane/testing/dynamic_source_test.exs b/test/membrane/testing/dynamic_source_test.exs index 1abdc69c0..ba0c52a38 100644 --- a/test/membrane/testing/dynamic_source_test.exs +++ b/test/membrane/testing/dynamic_source_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.Testing.DynamicSourceTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.ChildrenSpec import Membrane.Testing.Assertions diff --git a/test/membrane/testing/endpoint_test.exs b/test/membrane/testing/endpoint_test.exs index 92a91f98a..6c9e02f86 100644 --- a/test/membrane/testing/endpoint_test.exs +++ b/test/membrane/testing/endpoint_test.exs @@ -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} diff --git a/test/membrane/testing/mock_resource_guard_test.exs b/test/membrane/testing/mock_resource_guard_test.exs index bce3800e1..7721de90f 100644 --- a/test/membrane/testing/mock_resource_guard_test.exs +++ b/test/membrane/testing/mock_resource_guard_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.Testing.MockResourceGuardTest do - use ExUnit.Case + use ExUnit.Case, async: true doctest Membrane.Testing.MockResourceGuard end diff --git a/test/membrane/testing/pipeline_assertions_test.exs b/test/membrane/testing/pipeline_assertions_test.exs index 89c22c670..8c1cac817 100644 --- a/test/membrane/testing/pipeline_assertions_test.exs +++ b/test/membrane/testing/pipeline_assertions_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.Testing.PipelineAssertionsTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.Testing.Assertions diff --git a/test/membrane/testing/pipeline_test.exs b/test/membrane/testing/pipeline_test.exs index 0f4ddc938..768842193 100644 --- a/test/membrane/testing/pipeline_test.exs +++ b/test/membrane/testing/pipeline_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.Testing.PipelineTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.ChildrenSpec import Membrane.Testing.Assertions diff --git a/test/membrane/testing/sink_test.exs b/test/membrane/testing/sink_test.exs index fa76c8c23..d37dc7c7a 100644 --- a/test/membrane/testing/sink_test.exs +++ b/test/membrane/testing/sink_test.exs @@ -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 diff --git a/test/membrane/testing/source_test.exs b/test/membrane/testing/source_test.exs index f73335b45..270bda7af 100644 --- a/test/membrane/testing/source_test.exs +++ b/test/membrane/testing/source_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.Testing.SourceTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.ChildrenSpec import Membrane.Testing.Assertions diff --git a/test/membrane/utility_supervisor_test.exs b/test/membrane/utility_supervisor_test.exs index 4dc387d61..0aba5ce10 100644 --- a/test/membrane/utility_supervisor_test.exs +++ b/test/membrane/utility_supervisor_test.exs @@ -1,5 +1,5 @@ defmodule Membrane.UtilitySupervisorTest do - use ExUnit.Case + use ExUnit.Case, async: true import Membrane.ChildrenSpec import Membrane.Testing.Assertions diff --git a/test/test_helper.exs b/test/test_helper.exs index 7d7b5860b..10efabeb7 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,2 +1,6 @@ +# needed for testing distribution features +System.cmd("epmd", ["-daemon"]) +Node.start(:"my_node@127.0.0.1", :longnames) + ExUnit.configure(formatters: [ExUnit.CLIFormatter, JUnitFormatter]) ExUnit.start(exclude: [:long_running], capture_log: true, assert_receive_timeout: 500) From 20fa3e2f82ba196332434433f6e277d19d5f78ee Mon Sep 17 00:00:00 2001 From: Mateusz Front Date: Thu, 13 Jul 2023 16:13:34 +0200 Subject: [PATCH 2/2] nest sync module into ClockTest --- test/membrane/clock_test.exs | 48 ++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/test/membrane/clock_test.exs b/test/membrane/clock_test.exs index 12a143cdc..85a20b9eb 100644 --- a/test/membrane/clock_test.exs +++ b/test/membrane/clock_test.exs @@ -1,27 +1,3 @@ -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 - defmodule Membrane.ClockTest do use ExUnit.Case, async: true @@ -270,4 +246,28 @@ defmodule Membrane.ClockTest do defp random_time, do: :rand.uniform(10_000) defp ms_to_ns(e), do: e * 1_000_000 + + defmodule 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 end