From df42739c04805ee1a400310b3ebabb3924f989ab Mon Sep 17 00:00:00 2001 From: akash-akya Date: Sat, 21 Sep 2024 23:44:11 +0530 Subject: [PATCH] Update --- lib/ex_cmd/process.ex | 14 +++++++------- test/ex_cmd/process_test.exs | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/ex_cmd/process.ex b/lib/ex_cmd/process.ex index 4aa3a6e..15acdeb 100644 --- a/lib/ex_cmd/process.ex +++ b/lib/ex_cmd/process.ex @@ -196,7 +196,7 @@ defmodule ExCmd.Process do # sleep command does not watch for stdin or stdout, so closing the # pipe does not terminate the sleep command. iex> {:ok, p} = Process.start_link(~w(sleep 100000000)) # sleep indefinitely - iex> Process.await_exit(p, 500) # ensure `await_exit` finish within `500ms`. By default it waits for 5s + iex> Process.await_exit(p, 1000) # ensure `await_exit` finish within `1000ms`. By default it waits for 5s {:error, :killed} # command exit due to SIGTERM ``` @@ -214,16 +214,16 @@ defmodule ExCmd.Process do ``` # bc is a calculator, which reads from stdin and writes output to stdout - iex> {:ok, p} = Process.start_link(~w(bc)) - iex> Process.write(p, "1 + 1\n") # there must be new-line to indicate the end of the input line + iex> {:ok, p} = Process.start_link(~w(cat)) + iex> Process.write(p, "hello\n") # there must be new-line to indicate the end of the input line :ok iex> Process.read(p) - {:ok, "2\n"} - iex> Process.write(p, "2 * 10 + 1\n") + {:ok, "hello\n"} + iex> Process.write(p, "world\n") :ok iex> Process.read(p) - {:ok, "21\n"} - # We must close stdin to signal the `bc` command that we are done. + {:ok, "world\n"} + # We must close stdin to signal the command that we are done. # since `await_exit` implicitly closes the pipes, in this case we don't have to iex> Process.await_exit(p) {:ok, 0} diff --git a/test/ex_cmd/process_test.exs b/test/ex_cmd/process_test.exs index 1ae9987..b5f0834 100644 --- a/test/ex_cmd/process_test.exs +++ b/test/ex_cmd/process_test.exs @@ -199,8 +199,8 @@ defmodule ExCmd.ProcessTest do end test "if await_exit kills the program" do - {:ok, s} = Process.start_link(~w(sleep 10000)) - assert_killed(Process.await_exit(s, 500)) + {:ok, s} = Process.start_link(~w(sleep 10000), log: :stderr) + assert_killed(Process.await_exit(s, 1000)) end test "if external program terminates on process exit" do @@ -259,8 +259,8 @@ defmodule ExCmd.ProcessTest do assert {:ok, "ignored signals\n" <> _} = Process.read(s) - # attempt to kill the process after 200ms - assert_killed(Process.await_exit(s, 200)) + # attempt to kill the process after 1000ms + assert_killed(Process.await_exit(s, 1000)) refute os_process_alive?(os_pid) refute Elixir.Process.alive?(s.pid) @@ -345,7 +345,7 @@ defmodule ExCmd.ProcessTest do test "if ex_cmd process is *NOT* terminated on owner exit, if any pipe owner is alive" do parent = self() - {:ok, s} = Process.start_link(~w(cat), log: :stderr) + {:ok, s} = Process.start_link(~w(cat)) io_proc = spawn_link(fn -> @@ -361,7 +361,7 @@ defmodule ExCmd.ProcessTest do end # external process will be killed with SIGTERM (143) - assert_killed(Process.await_exit(s, 200)) + assert_killed(Process.await_exit(s, 1000)) # wait for messages to propagate, if there are any :timer.sleep(100) @@ -407,7 +407,7 @@ defmodule ExCmd.ProcessTest do :owner_changed -> :ok end - assert_killed(Process.await_exit(s, 200)) + _ = Process.await_exit(s, 1000) refute os_process_alive?(os_pid) assert {:error, :epipe} == Task.await(task) @@ -701,7 +701,7 @@ defmodule ExCmd.ProcessTest do receive do {^sender, term} -> term after - 1000 -> + 3000 -> raise "recv timeout" end end