Skip to content

Commit

Permalink
Fix race condition in serving tests (#1554)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored Oct 30, 2024
1 parent a21d30b commit 4936aa0
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions nx/test/nx/serving_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,10 @@ defmodule Nx.ServingTest do
# One task should succeed and the other terminate
assert_receive {:DOWN, ref, _, _,
{{%RuntimeError{}, _}, {Nx.Serving, :local_batched_run, [_, _]}}}
when ref in [ref1, ref2]

assert_receive {:DOWN, ref, _, _, :normal} when ref in [ref1, ref2]
assert [other_ref] = [ref1, ref2] -- [ref]

assert_receive {:DOWN, ^other_ref, _, _, :normal}
refute_received {:execute, _partition, _executor}
end

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

assert_receive {:execute, 0, executor}
send(serving_pid, {:system, {self(), make_ref()}, {:terminate, :shutdown}})
send(executor, :continue)

# One task should succeed and the other terminate
assert_receive {:DOWN, ref, _, _, :normal}
when ref in [ref1, ref2]

# The queued caller should be terminated with :noproc right away
assert_receive {:DOWN, ref, _, _, {:noproc, {Nx.Serving, :local_batched_run, [_, _]}}}
when ref in [ref1, ref2]
assert [other_ref] = [ref1, ref2] -- [ref]

# The executing caller should be able to finish
send(executor, :continue)
assert_receive {:DOWN, ^other_ref, _, _, :normal}

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

assert_receive {:execute, 0, executor}
send(serving_pid, {:system, {self(), make_ref()}, {:terminate, :shutdown}})
send(executor, :continue)

# One task should succeed and the other terminate
assert_receive {:DOWN, ref, _, _, :normal}
when ref in [ref1, ref2]

# The stacked caller should be terminated with :noproc right away
assert_receive {:DOWN, ref, _, _, {:noproc, {Nx.Serving, :local_batched_run, [_, _]}}}
when ref in [ref1, ref2]
assert [other_ref] = [ref1, ref2] -- [ref]

# The executing caller should be able to finish
send(executor, :continue)
assert_receive {:DOWN, ^other_ref, _, _, :normal}

refute_received {:execute, _partition, _executor}
end
Expand Down

0 comments on commit 4936aa0

Please sign in to comment.