diff --git a/Dockerfile b/Dockerfile index af1ee3d..2483e99 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,8 +9,14 @@ ENV LANG=C.UTF-8 # install build dependencies RUN apt update && \ apt upgrade -y && \ - apt install -y --no-install-recommends git build-essential nodejs yarnpkg && \ - apt clean -y && rm -rf /var/lib/apt/lists/* + apt install -y --no-install-recommends git build-essential curl ca-certificates gnupg && \ + mkdir -p /etc/apt/keyrings && \ + curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \ + apt update && \ + apt install -y --no-install-recommends nodejs && \ + apt clean -y && rm -rf /var/lib/apt/lists/* && \ + npm install -g yarn # prepare build dir RUN mkdir /app @@ -31,7 +37,7 @@ RUN mix deps.compile # build assets COPY assets assets -RUN cd assets && yarnpkg install && yarnpkg run webpack --mode production +RUN cd assets && yarn install && yarn run webpack --mode production RUN mix phx.digest # build project diff --git a/test/diff/tmp_dir_test.exs b/test/diff/tmp_dir_test.exs index e95dddd..4943135 100644 --- a/test/diff/tmp_dir_test.exs +++ b/test/diff/tmp_dir_test.exs @@ -15,14 +15,16 @@ defmodule Diff.TmpDirTest do test "cleanup on normal process exit" do test_pid = self() - Task.start(fn -> - file = Diff.TmpDir.tmp_file("test") - dir = Diff.TmpDir.tmp_dir("test") - send(test_pid, {:paths, file, dir}) - end) - + {:ok, task_pid} = + Task.start(fn -> + file = Diff.TmpDir.tmp_file("test") + dir = Diff.TmpDir.tmp_dir("test") + send(test_pid, {:paths, file, dir}) + end) + + ref = Process.monitor(task_pid) assert_receive {:paths, file, dir} - Process.sleep(100) + wait_for_cleanup(task_pid, ref) refute File.exists?(file) refute File.exists?(dir) @@ -32,15 +34,17 @@ defmodule Diff.TmpDirTest do test "cleanup on process crash" do test_pid = self() - Task.start(fn -> - file = Diff.TmpDir.tmp_file("test") - dir = Diff.TmpDir.tmp_dir("test") - send(test_pid, {:paths, file, dir}) - raise "crash" - end) + {:ok, task_pid} = + Task.start(fn -> + file = Diff.TmpDir.tmp_file("test") + dir = Diff.TmpDir.tmp_dir("test") + send(test_pid, {:paths, file, dir}) + raise "crash" + end) + ref = Process.monitor(task_pid) assert_receive {:paths, file, dir} - Process.sleep(100) + wait_for_cleanup(task_pid, ref) refute File.exists?(file) refute File.exists?(dir) @@ -49,19 +53,21 @@ defmodule Diff.TmpDirTest do test "multiple paths for one process" do test_pid = self() - Task.start(fn -> - paths = - for i <- 1..5 do - file = Diff.TmpDir.tmp_file("test-#{i}") - dir = Diff.TmpDir.tmp_dir("test-#{i}") - {file, dir} - end + {:ok, task_pid} = + Task.start(fn -> + paths = + for i <- 1..5 do + file = Diff.TmpDir.tmp_file("test-#{i}") + dir = Diff.TmpDir.tmp_dir("test-#{i}") + {file, dir} + end - send(test_pid, {:paths, paths}) - end) + send(test_pid, {:paths, paths}) + end) + ref = Process.monitor(task_pid) assert_receive {:paths, paths} - Process.sleep(100) + wait_for_cleanup(task_pid, ref) for {file, dir} <- paths do refute File.exists?(file) @@ -76,4 +82,10 @@ defmodule Diff.TmpDirTest do assert File.exists?(file) assert File.dir?(dir) end + + defp wait_for_cleanup(task_pid, ref) do + assert_receive {:DOWN, ^ref, :process, ^task_pid, _}, 5000 + # Sync with the GenServer to ensure the :DOWN cleanup has been processed + :sys.get_state(Diff.TmpDir) + end end