Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
60 changes: 36 additions & 24 deletions test/diff/tmp_dir_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Loading