Skip to content

Commit

Permalink
Load test in Tmp.LoadTest
Browse files Browse the repository at this point in the history
  • Loading branch information
preciz committed Jul 13, 2024
1 parent 27379f3 commit c4cc1ec
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/tmp/load_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
defmodule Tmp.LoadTest do
use ExUnit.Case, async: true

defmodule TestTmp do
use Tmp
end

@job_count 10_000

setup do
start_supervised!({TestTmp, name: TestTmp})
:ok
end

test "handles #{@job_count} concurrent jobs" do
task_results =
Task.async_stream(
1..@job_count,
fn _ ->
TestTmp.dir(
fn tmp_dir ->
# Verify that the temporary directory has the correct prefix
assert Path.basename(tmp_dir) =~ ~r/^tmp_load_test-\d+-[a-f0-9]+$/
file_path = Path.join(tmp_dir, "test_file")
File.write!(file_path, "test content")
assert File.read!(file_path) == "test content"
:ok
end,
prefix: "tmp_load_test"
)
end,
max_concurrency: System.schedulers_online() * 2,
timeout: :infinity
)
|> Enum.to_list()

assert Enum.count(task_results) == @job_count
assert Enum.all?(task_results, &match?({:ok, :ok}, &1))

# Ensure all temporary directories are cleaned up
Process.sleep(1000)
assert Path.wildcard(Path.join(System.tmp_dir(), "tmp_load_test-*")) == []
end
end

0 comments on commit c4cc1ec

Please sign in to comment.