Skip to content
This repository was archived by the owner on Jul 17, 2026. It is now read-only.

Commit 9ef2a43

Browse files
committed
Update Node to 22 and fix flaky TmpDir test
Install Node 22 from NodeSource instead of Node 18 from Debian apt since webpack-cli 7 requires Node >= 20.9.0. Fix flaky TmpDir cleanup test by replacing Process.sleep with proper process monitor and GenServer sync.
1 parent 263df0a commit 9ef2a43

2 files changed

Lines changed: 42 additions & 25 deletions

File tree

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ ENV LANG=C.UTF-8
99
# install build dependencies
1010
RUN apt update && \
1111
apt upgrade -y && \
12-
apt install -y --no-install-recommends git build-essential nodejs yarnpkg && \
12+
apt install -y --no-install-recommends git build-essential curl ca-certificates gnupg && \
13+
mkdir -p /etc/apt/keyrings && \
14+
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
15+
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 && \
16+
apt update && \
17+
apt install -y --no-install-recommends nodejs yarnpkg && \
1318
apt clean -y && rm -rf /var/lib/apt/lists/*
1419

1520
# prepare build dir

test/diff/tmp_dir_test.exs

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ defmodule Diff.TmpDirTest do
1515
test "cleanup on normal process exit" do
1616
test_pid = self()
1717

18-
Task.start(fn ->
19-
file = Diff.TmpDir.tmp_file("test")
20-
dir = Diff.TmpDir.tmp_dir("test")
21-
send(test_pid, {:paths, file, dir})
22-
end)
23-
18+
{:ok, task_pid} =
19+
Task.start(fn ->
20+
file = Diff.TmpDir.tmp_file("test")
21+
dir = Diff.TmpDir.tmp_dir("test")
22+
send(test_pid, {:paths, file, dir})
23+
end)
24+
25+
ref = Process.monitor(task_pid)
2426
assert_receive {:paths, file, dir}
25-
Process.sleep(100)
27+
wait_for_cleanup(task_pid, ref)
2628

2729
refute File.exists?(file)
2830
refute File.exists?(dir)
@@ -32,15 +34,17 @@ defmodule Diff.TmpDirTest do
3234
test "cleanup on process crash" do
3335
test_pid = self()
3436

35-
Task.start(fn ->
36-
file = Diff.TmpDir.tmp_file("test")
37-
dir = Diff.TmpDir.tmp_dir("test")
38-
send(test_pid, {:paths, file, dir})
39-
raise "crash"
40-
end)
37+
{:ok, task_pid} =
38+
Task.start(fn ->
39+
file = Diff.TmpDir.tmp_file("test")
40+
dir = Diff.TmpDir.tmp_dir("test")
41+
send(test_pid, {:paths, file, dir})
42+
raise "crash"
43+
end)
4144

45+
ref = Process.monitor(task_pid)
4246
assert_receive {:paths, file, dir}
43-
Process.sleep(100)
47+
wait_for_cleanup(task_pid, ref)
4448

4549
refute File.exists?(file)
4650
refute File.exists?(dir)
@@ -49,19 +53,21 @@ defmodule Diff.TmpDirTest do
4953
test "multiple paths for one process" do
5054
test_pid = self()
5155

52-
Task.start(fn ->
53-
paths =
54-
for i <- 1..5 do
55-
file = Diff.TmpDir.tmp_file("test-#{i}")
56-
dir = Diff.TmpDir.tmp_dir("test-#{i}")
57-
{file, dir}
58-
end
56+
{:ok, task_pid} =
57+
Task.start(fn ->
58+
paths =
59+
for i <- 1..5 do
60+
file = Diff.TmpDir.tmp_file("test-#{i}")
61+
dir = Diff.TmpDir.tmp_dir("test-#{i}")
62+
{file, dir}
63+
end
5964

60-
send(test_pid, {:paths, paths})
61-
end)
65+
send(test_pid, {:paths, paths})
66+
end)
6267

68+
ref = Process.monitor(task_pid)
6369
assert_receive {:paths, paths}
64-
Process.sleep(100)
70+
wait_for_cleanup(task_pid, ref)
6571

6672
for {file, dir} <- paths do
6773
refute File.exists?(file)
@@ -76,4 +82,10 @@ defmodule Diff.TmpDirTest do
7682
assert File.exists?(file)
7783
assert File.dir?(dir)
7884
end
85+
86+
defp wait_for_cleanup(task_pid, ref) do
87+
assert_receive {:DOWN, ^ref, :process, ^task_pid, _}, 5000
88+
# Sync with the GenServer to ensure the :DOWN cleanup has been processed
89+
:sys.get_state(Diff.TmpDir)
90+
end
7991
end

0 commit comments

Comments
 (0)