Skip to content

Commit 4936aa0

Browse files
Fix race condition in serving tests (#1554)
1 parent a21d30b commit 4936aa0

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

nx/test/nx/serving_test.exs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,10 @@ defmodule Nx.ServingTest do
607607
# One task should succeed and the other terminate
608608
assert_receive {:DOWN, ref, _, _,
609609
{{%RuntimeError{}, _}, {Nx.Serving, :local_batched_run, [_, _]}}}
610-
when ref in [ref1, ref2]
611610

612-
assert_receive {:DOWN, ref, _, _, :normal} when ref in [ref1, ref2]
611+
assert [other_ref] = [ref1, ref2] -- [ref]
612+
613+
assert_receive {:DOWN, ^other_ref, _, _, :normal}
613614
refute_received {:execute, _partition, _executor}
614615
end
615616

@@ -631,14 +632,14 @@ defmodule Nx.ServingTest do
631632

632633
assert_receive {:execute, 0, executor}
633634
send(serving_pid, {:system, {self(), make_ref()}, {:terminate, :shutdown}})
634-
send(executor, :continue)
635-
636-
# One task should succeed and the other terminate
637-
assert_receive {:DOWN, ref, _, _, :normal}
638-
when ref in [ref1, ref2]
639635

636+
# The queued caller should be terminated with :noproc right away
640637
assert_receive {:DOWN, ref, _, _, {:noproc, {Nx.Serving, :local_batched_run, [_, _]}}}
641-
when ref in [ref1, ref2]
638+
assert [other_ref] = [ref1, ref2] -- [ref]
639+
640+
# The executing caller should be able to finish
641+
send(executor, :continue)
642+
assert_receive {:DOWN, ^other_ref, _, _, :normal}
642643

643644
refute_received {:execute, _partition, _executor}
644645
end
@@ -661,14 +662,14 @@ defmodule Nx.ServingTest do
661662

662663
assert_receive {:execute, 0, executor}
663664
send(serving_pid, {:system, {self(), make_ref()}, {:terminate, :shutdown}})
664-
send(executor, :continue)
665-
666-
# One task should succeed and the other terminate
667-
assert_receive {:DOWN, ref, _, _, :normal}
668-
when ref in [ref1, ref2]
669665

666+
# The stacked caller should be terminated with :noproc right away
670667
assert_receive {:DOWN, ref, _, _, {:noproc, {Nx.Serving, :local_batched_run, [_, _]}}}
671-
when ref in [ref1, ref2]
668+
assert [other_ref] = [ref1, ref2] -- [ref]
669+
670+
# The executing caller should be able to finish
671+
send(executor, :continue)
672+
assert_receive {:DOWN, ^other_ref, _, _, :normal}
672673

673674
refute_received {:execute, _partition, _executor}
674675
end

0 commit comments

Comments
 (0)