Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition in tests with ports #2

Merged
merged 1 commit into from
Jun 10, 2024
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
10 changes: 6 additions & 4 deletions test/statix/config_test.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
defmodule Statix.ConfigTest do
use Statix.TestCase, async: false
@server_port 8325

use Statix.TestCase, async: false, port: @server_port

use Statix, runtime_config: true

test "connect/1" do
connect(tags: ["tag:test"], prefix: "foo")
connect(tags: ["tag:test"], prefix: "foo", port: @server_port)

increment("sample", 2)
assert_receive {:test_server, _, "foo.sample:2|c|#tag:test"}
Expand All @@ -13,7 +15,7 @@ defmodule Statix.ConfigTest do
test "global tags when present" do
Application.put_env(:statix, :tags, ["tag:test"])

connect()
connect(port: @server_port)

increment("sample", 3)
assert_receive {:test_server, _, "sample:3|c|#tag:test"}
Expand All @@ -27,7 +29,7 @@ defmodule Statix.ConfigTest do
test "global connection-specific tags" do
Application.put_env(:statix, __MODULE__, tags: ["tag:test"])

connect()
connect(port: @server_port)

set("sample", 4)
assert_receive {:test_server, _, "sample:4|s|#tag:test"}
Expand Down
6 changes: 4 additions & 2 deletions test/statix/pool_test.exs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
defmodule Statix.PoolingTest do
use Statix.TestCase
@server_port 8425

use Statix.TestCase, port: @server_port

use Statix, runtime_config: true

@pool_size 3

setup do
connect(pool_size: @pool_size)
connect(pool_size: @pool_size, port: @server_port)
end

test "starts :pool_size number of ports and randomly picks one" do
Expand Down
6 changes: 4 additions & 2 deletions test/statix_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
runtime_config? = System.get_env("STATIX_TEST_RUNTIME_CONFIG") in ["1", "true"]

defmodule StatixTest do
use Statix.TestCase
@server_port 8525

use Statix.TestCase, port: @server_port

import ExUnit.CaptureLog

Expand All @@ -13,7 +15,7 @@ defmodule StatixTest do
end

setup do
connect()
connect(port: @server_port)
end

test "increment/1,2,3" do
Expand Down
Loading