This repository has been archived on 2024-01-29. You can view files and clone it, but cannot push or open issues or pull requests.
distributed_system_coursework/lib/test_util.ex

26 lines
794 B
Elixir
Executable File

defmodule TestUtil do
def get_node(host), do: String.to_atom(UUID.uuid1 <> "@" <> host)
def get_dist_config(host, n) do
for i <- (1..n), into: %{}, do:
{String.to_atom("p"<>to_string(i)), {get_node(host), {:val, Enum.random(201..210)}}}
end
def get_local_config(n) do
for i <- 1..n, into: %{}, do:
{String.to_atom("p"<>to_string(i)), {:local, {:val, Enum.random(201..210)}}}
end
def pause_stderr(d) do
my_pid = self()
spawn(fn -> pid=Process.whereis(:standard_error);
:erlang.suspend_process(pid);
send(my_pid, {:suspended})
Process.sleep(d);
:erlang.resume_process(pid) end)
receive do
{:suspended} -> :done
end
end
end