Skip to content

Commit 8ef2684

Browse files
committed
Avoid timing issues in CI
1 parent 3320a11 commit 8ef2684

File tree

1 file changed

+3
-118
lines changed

1 file changed

+3
-118
lines changed

lib/ex_unit/test/ex_unit_test.exs

Lines changed: 3 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -715,123 +715,6 @@ defmodule ExUnitTest do
715715
assert_receive {:tmp_dir, tmp_dir2} when tmp_dir1 != tmp_dir2
716716
end
717717

718-
test "async tests run concurrently" do
719-
Process.register(self(), :async_tests)
720-
721-
defmodule FirstAsyncTest do
722-
use ExUnit.Case, async: true
723-
724-
test "first test" do
725-
send(:async_tests, {:first_test, :started})
726-
Process.sleep(10)
727-
assert true
728-
send(:async_tests, {:first_test, :finished})
729-
end
730-
end
731-
732-
defmodule SecondAsyncTest do
733-
use ExUnit.Case, async: true
734-
735-
test "second test" do
736-
send(:async_tests, {:second_test, :started})
737-
Process.sleep(15)
738-
assert true
739-
send(:async_tests, {:second_test, :finished})
740-
end
741-
end
742-
743-
configure_and_reload_on_exit(max_cases: 2)
744-
745-
test_task =
746-
Task.async(fn ->
747-
capture_io(fn -> ExUnit.run() end)
748-
end)
749-
750-
# Expected test distribution through time
751-
#
752-
# Time (ms): 0 10 20
753-
# |-----|-----|
754-
# CPU0: ( 1 )
755-
# CPU1: ( 2 )
756-
assert_receive({:first_test, :started}, 5)
757-
assert_receive({:second_test, :started}, 5)
758-
759-
# make sure we don't leave the task running after the outer test finishes
760-
Task.await(test_task)
761-
end
762-
763-
test "async tests run concurrently respecting groups" do
764-
Process.register(self(), :async_grouped_tests)
765-
766-
defmodule RedOneTest do
767-
use ExUnit.Case, async: true, group: :red
768-
769-
test "red one test" do
770-
send(:async_grouped_tests, {:red_one, :started})
771-
Process.sleep(30)
772-
assert true
773-
send(:async_grouped_tests, {:red_one, :finished})
774-
end
775-
end
776-
777-
defmodule RedTwoTest do
778-
use ExUnit.Case, async: true, group: :red
779-
780-
test "red two test" do
781-
send(:async_grouped_tests, {:red_two, :started})
782-
Process.sleep(10)
783-
assert true
784-
send(:async_grouped_tests, {:red_two, :finished})
785-
end
786-
end
787-
788-
defmodule BlueOneTest do
789-
use ExUnit.Case, async: true, group: :blue
790-
791-
test "blue one test" do
792-
send(:async_grouped_tests, {:blue_one, :started})
793-
Process.sleep(10)
794-
assert true
795-
send(:async_grouped_tests, {:blue_one, :finished})
796-
end
797-
end
798-
799-
defmodule BlueTwoTest do
800-
use ExUnit.Case, async: true, group: :blue
801-
802-
test "blue two test" do
803-
send(:async_grouped_tests, {:blue_two, :started})
804-
Process.sleep(10)
805-
assert true
806-
send(:async_grouped_tests, {:blue_two, :finished})
807-
end
808-
end
809-
810-
configure_and_reload_on_exit(max_cases: 4)
811-
812-
test_task =
813-
Task.async(fn ->
814-
capture_io(fn -> ExUnit.run() end)
815-
end)
816-
817-
# Expected test distribution through time
818-
#
819-
# Time (ms): 0 10 20 30 40
820-
# |-----|-----|-----|-----|
821-
# CPU0: ( R1 )( R2 )
822-
# CPU1: ( B1 )( B2 )
823-
assert_receive({:red_one, :started}, 5)
824-
assert_receive({:blue_one, :started}, 5)
825-
refute_receive({:red_two, :started}, 25)
826-
assert_received({:blue_one, :finished})
827-
assert_received({:blue_two, :started})
828-
assert_receive({:blue_two, :finished}, 15)
829-
assert_receive({:red_two, :started}, 15)
830-
831-
# make sure we don't leave the task running after the outer test finishes
832-
Task.await(test_task)
833-
end
834-
835718
describe "after_suite/1" do
836719
test "executes all callbacks set in reverse order" do
837720
Process.register(self(), :after_suite_test_process)
@@ -1223,6 +1106,7 @@ defmodule ExUnitTest do
12231106
use ExUnit.Case, async: true, group: :red
12241107

12251108
test "red one test" do
1109+
Process.sleep(5)
12261110
assert true
12271111
end
12281112
end
@@ -1231,6 +1115,7 @@ defmodule ExUnitTest do
12311115
use ExUnit.Case, async: true, group: :blue
12321116

12331117
test "blue one test" do
1118+
Process.sleep(5)
12341119
assert true
12351120
end
12361121
end
@@ -1251,7 +1136,7 @@ defmodule ExUnitTest do
12511136
end
12521137
end
12531138

1254-
configure_and_reload_on_exit(trace: true)
1139+
configure_and_reload_on_exit(trace: true, max_cases: 2)
12551140

12561141
output =
12571142
capture_io(fn ->

0 commit comments

Comments
 (0)