Skip to content

Commit be16fee

Browse files
committed
fix: prevent zombie mix processes from integration tests
1 parent dd9cbd4 commit be16fee

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

priv/zombie_killer

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
# Modified version of port wrapper that supports sending a
4+
# string to the wrapper program's stdin
5+
6+
# Run the program in the background, sending
7+
# $ZOMBIE_KILLER_INPUT as stdin
8+
echo -e "$ZOMBIE_KILLER_INPUT" | exec "$@" &
9+
program_pid=$!
10+
11+
# Silence warnings from here on
12+
exec >/dev/null 2>&1
13+
14+
# Read from stdin in the background and kill process
15+
# when stdin closes
16+
(
17+
while read; do :; done
18+
kill -KILL $program_pid
19+
) <&0 &
20+
stdin_monitor_pid=$!
21+
22+
# Clean up
23+
wait $program_pid
24+
ret=$?
25+
kill -KILL $stdin_monitor_pid
26+
exit $ret

test/support/integration.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ defmodule Mneme.Integration do
6161
File.write!(file_path, test.test_code)
6262

6363
test_command = """
64-
echo "#{test.test_input}" | \
65-
CI=false mix test #{file_path} --seed 0 \
64+
ZOMBIE_KILLER_INPUT=#{inspect(test.test_input)} \
65+
CI=false \
66+
#{zombie_killer()} mix test #{file_path} --seed 0 \
6667
"""
6768

6869
test_command =
@@ -108,6 +109,10 @@ defmodule Mneme.Integration do
108109
end
109110
end
110111

112+
defp zombie_killer do
113+
:mneme |> :code.priv_dir() |> Path.join("zombie_killer")
114+
end
115+
111116
defp debug_setup(nil, _), do: :ok
112117

113118
defp debug_setup("", test) do

0 commit comments

Comments
 (0)