Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
akash-akya committed Sep 13, 2024
1 parent 959b23e commit 2e1d839
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions test/ex_cmd/process_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ExCmd.ProcessTest do
alias ExCmd.Process
alias ExCmd.Process.{Pipe, State}

# doctest ExCmd.Process
doctest ExCmd.Process

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 24.x / Elixir 1.13.x

doctest module ExCmd.Process (3) (ExCmd.ProcessTest)

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 24.x / Elixir 1.13.x

doctest module ExCmd.Process (4) (ExCmd.ProcessTest)

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 26.x / Elixir 1.16.x

doctest module ExCmd.Process (4) (ExCmd.ProcessTest)

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 26.x / Elixir 1.16.x

doctest module ExCmd.Process (3) (ExCmd.ProcessTest)

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 25.x / Elixir 1.14.x

doctest module ExCmd.Process (3) (ExCmd.ProcessTest)

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 25.x / Elixir 1.14.x

doctest module ExCmd.Process (4) (ExCmd.ProcessTest)

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 26.x / Elixir 1.15.x

doctest module ExCmd.Process (3) (ExCmd.ProcessTest)

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 26.x / Elixir 1.15.x

doctest module ExCmd.Process (4) (ExCmd.ProcessTest)

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 23.x / Elixir 1.12.x

doctest module ExCmd.Process (4) (ExCmd.ProcessTest)

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 23.x / Elixir 1.12.x

doctest module ExCmd.Process (3) (ExCmd.ProcessTest)

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Windows OTP 25 / Elixir 1.14

doctest module ExCmd.Process (4) (ExCmd.ProcessTest)

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Windows OTP 25 / Elixir 1.14

doctest module ExCmd.Process (5) (ExCmd.ProcessTest)

Check failure on line 7 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Windows OTP 25 / Elixir 1.14

doctest module ExCmd.Process (3) (ExCmd.ProcessTest)

describe "pipes" do
test "reading from stdout" do

Check failure on line 10 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 26.x / Elixir 1.16.x

test pipes reading from stdout (ExCmd.ProcessTest)
Expand Down Expand Up @@ -190,20 +190,60 @@ defmodule ExCmd.ProcessTest do
end

describe "process termination" do
test "if process is terminated automatically on owner exit" do
pid = self()

spawn_link(fn ->
{:ok, s} = Process.start_link(~w(cat))
{:ok, os_pid} = Process.os_pid(s)
send(pid, os_pid)
end)

os_pid =
receive do
os_pid -> os_pid
end

:timer.sleep(500)

refute os_process_alive?(os_pid)
end

test "if await_exit closes stdin implicitly" do
{:ok, s} = Process.start_link(~w(cat))
assert {:ok, 0} = Process.await_exit(s, 100)
end

test "if await_exit kills the program" do

Check failure on line 217 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Windows OTP 25 / Elixir 1.14

test process termination if await_exit kills the program (ExCmd.ProcessTest)
{:ok, s} = Process.start_link(~w(sleep 1000))
assert {:error, :killed} = Process.await_exit(s, 100)
end

test "if external program terminates on process exit" do

Check failure on line 222 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Windows OTP 25 / Elixir 1.14

test process termination if external program terminates on process exit (ExCmd.ProcessTest)
{:ok, s} = Process.start_link(~w(cat))
{:ok, os_pid} = Process.os_pid(s)

assert os_process_alive?(os_pid)

:ok = Process.close_stdin(s)
# TODO: fixeme, no read is required
:eof = Process.read(s)
:timer.sleep(2000)
assert :eof = Process.read(s)
:timer.sleep(1000)

refute os_process_alive?(os_pid)
end

test "read after command finishes" do
{:ok, s} = Process.start_link(~w(cat))
{:ok, os_pid} = Process.os_pid(s)
assert os_process_alive?(os_pid)

assert :ok == Process.write(s, "hello")
:ok = Process.close_stdin(s)
:timer.sleep(1000)

assert {:ok, "hello"} == Process.read(s)
end

test "watcher kills external command on process without exit_await" do

Check failure on line 247 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 24.x / Elixir 1.13.x

test process termination watcher kills external command on process without exit_await (ExCmd.ProcessTest)

Check failure on line 247 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 26.x / Elixir 1.16.x

test process termination watcher kills external command on process without exit_await (ExCmd.ProcessTest)

Check failure on line 247 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 25.x / Elixir 1.14.x

test process termination watcher kills external command on process without exit_await (ExCmd.ProcessTest)

Check failure on line 247 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 26.x / Elixir 1.15.x

test process termination watcher kills external command on process without exit_await (ExCmd.ProcessTest)

Check failure on line 247 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Linux OTP 23.x / Elixir 1.12.x

test process termination watcher kills external command on process without exit_await (ExCmd.ProcessTest)

Check failure on line 247 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Windows OTP 25 / Elixir 1.14

test process termination watcher kills external command on process without exit_await (ExCmd.ProcessTest)
{os_pid, s} =
Task.async(fn ->
Expand Down Expand Up @@ -481,7 +521,7 @@ defmodule ExCmd.ProcessTest do
Enum.sum(Enum.map(write_events, fn {:write, size} -> size end))

# There must be a read before write completes
assert hd(events) == {:read, 65_531}
assert {:read, _} = hd(events)
end

# this test does not work properly in linux
Expand Down

0 comments on commit 2e1d839

Please sign in to comment.