Skip to content

Commit 8141c5b

Browse files
committed
Fix race conditions in tests and reorder precompile workflow
Test fixes: Replace GenServer.stop with Process.exit and use try/catch to handle exits during cleanup, preventing flaky test failures. Workflow: Reorder steps to precompile before testing so tests validate the actual precompiled artifacts users will download.
1 parent f29d55d commit 8141c5b

File tree

6 files changed

+42
-43
lines changed

6 files changed

+42
-43
lines changed

.github/workflows/precompile.yml

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,18 @@ jobs:
3737
- name: Install dependencies
3838
run: mix deps.get
3939

40-
- name: Compile (for native x86_64 tests)
41-
run: mix compile
40+
- name: Precompile NIFs (native + cross-compile)
41+
run: |
42+
export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache
43+
mkdir -p $ELIXIR_MAKE_CACHE_DIR
44+
MIX_ENV=prod mix elixir_make.precompile
4245
4346
- name: Run tests on x86_64
4447
run: mix test --exclude integration
4548
env:
4649
CLICKHOUSE_HOST: localhost
4750
CLICKHOUSE_PORT: 9000
4851

49-
- name: Precompile NIFs (native + cross-compile)
50-
run: |
51-
export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache
52-
mkdir -p $ELIXIR_MAKE_CACHE_DIR
53-
MIX_ENV=prod mix elixir_make.precompile
54-
5552
- name: Upload artifacts to release
5653
uses: softprops/action-gh-release@v1
5754
if: startsWith(github.ref, 'refs/tags/')
@@ -99,21 +96,18 @@ jobs:
9996
sudo apt-get install -y build-essential cmake libssl-dev
10097
mix deps.get
10198
102-
- name: Compile
103-
run: mix compile
99+
- name: Precompile NIFs
100+
run: |
101+
export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache
102+
mkdir -p $ELIXIR_MAKE_CACHE_DIR
103+
MIX_ENV=prod mix elixir_make.precompile
104104
105105
- name: Run tests on ARM64
106106
run: mix test --exclude integration
107107
env:
108108
CLICKHOUSE_HOST: localhost
109109
CLICKHOUSE_PORT: 9000
110110

111-
- name: Precompile NIFs
112-
run: |
113-
export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache
114-
mkdir -p $ELIXIR_MAKE_CACHE_DIR
115-
MIX_ENV=prod mix elixir_make.precompile
116-
117111
- name: Upload artifacts to release
118112
uses: softprops/action-gh-release@v1
119113
if: startsWith(github.ref, 'refs/tags/')
@@ -191,18 +185,18 @@ jobs:
191185
brew install cmake openssl
192186
mix deps.get
193187
194-
- name: Run tests on x86_64 macOS
195-
run: mix test --exclude integration
196-
env:
197-
CLICKHOUSE_HOST: localhost
198-
CLICKHOUSE_PORT: 9000
199-
200188
- name: Precompile NIFs
201189
run: |
202190
export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache
203191
mkdir -p $ELIXIR_MAKE_CACHE_DIR
204192
MIX_ENV=prod mix elixir_make.precompile
205193
194+
- name: Run tests on x86_64 macOS
195+
run: mix test --exclude integration
196+
env:
197+
CLICKHOUSE_HOST: localhost
198+
CLICKHOUSE_PORT: 9000
199+
206200
- name: Upload artifacts to release
207201
uses: softprops/action-gh-release@v1
208202
if: startsWith(github.ref, 'refs/tags/')
@@ -264,18 +258,18 @@ jobs:
264258
brew install cmake openssl
265259
mix deps.get
266260
267-
- name: Run tests on ARM64 macOS
268-
run: mix test --exclude integration
269-
env:
270-
CLICKHOUSE_HOST: localhost
271-
CLICKHOUSE_PORT: 9000
272-
273261
- name: Precompile NIFs
274262
run: |
275263
export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache
276264
mkdir -p $ELIXIR_MAKE_CACHE_DIR
277265
MIX_ENV=prod mix elixir_make.precompile
278266
267+
- name: Run tests on ARM64 macOS
268+
run: mix test --exclude integration
269+
env:
270+
CLICKHOUSE_HOST: localhost
271+
CLICKHOUSE_PORT: 9000
272+
279273
- name: Upload artifacts to release
280274
uses: softprops/action-gh-release@v1
281275
if: startsWith(github.ref, 'refs/tags/')

test/bang_test.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ defmodule Chex.BangTest do
1515
if Process.alive?(conn) do
1616
try do
1717
Connection.execute(conn, "DROP TABLE IF EXISTS #{table}")
18-
rescue
19-
_ -> :ok
18+
catch
19+
:exit, _ -> :ok
2020
end
2121

22-
GenServer.stop(conn)
22+
# Use Process.exit to avoid race conditions
23+
Process.exit(conn, :normal)
2324
end
2425
end)
2526

test/block_test.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ defmodule Chex.BlockTest do
1515
if Process.alive?(conn) do
1616
try do
1717
Chex.Connection.execute(conn, "DROP TABLE IF EXISTS #{table}")
18-
rescue
19-
_ -> :ok
18+
catch
19+
:exit, _ -> :ok
2020
end
2121

22-
GenServer.stop(conn)
22+
# Use Process.exit to avoid race conditions
23+
Process.exit(conn, :normal)
2324
end
2425
end)
2526

test/connection_test.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ defmodule Chex.ConnectionTest do
1313
if Process.alive?(conn) do
1414
try do
1515
Chex.Connection.execute(conn, "DROP TABLE IF EXISTS #{table}")
16-
rescue
17-
_ -> :ok
16+
catch
17+
:exit, _ -> :ok
1818
end
1919

20-
GenServer.stop(conn)
20+
# Use Process.exit to avoid race conditions
21+
Process.exit(conn, :normal)
2122
end
2223
end)
2324

test/nesting_integration_test.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ defmodule Chex.NestingIntegrationTest do
1515
if Process.alive?(conn) do
1616
try do
1717
Connection.execute(conn, "DROP TABLE IF EXISTS #{table}")
18-
rescue
19-
_ -> :ok
18+
catch
19+
:exit, _ -> :ok
2020
end
2121

22-
GenServer.stop(conn)
22+
# Use Process.exit to avoid race conditions
23+
Process.exit(conn, :normal)
2324
end
2425
end)
2526

test/query_test.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ defmodule Chex.QueryTest do
1515
if Process.alive?(conn) do
1616
try do
1717
Connection.execute(conn, "DROP TABLE IF EXISTS #{table}")
18-
rescue
19-
_ -> :ok
18+
catch
19+
:exit, _ -> :ok
2020
end
2121

22-
GenServer.stop(conn)
22+
# Use Process.exit to avoid race conditions
23+
Process.exit(conn, :normal)
2324
end
2425
end)
2526

0 commit comments

Comments
 (0)