Hello friends, I have read this link: Ecto.Adapters.SQL.Sandbox — Ecto SQL v3.7.2, they said if we dont wan to drop a Genserver
like this:
** (exit) exited in: GenServer.call(#PID<0.1673.0>, {:push, :edit, %MishkaInstaller.PluginState{depend_type: :soft, depends: [], event: "event_one", extra: [], name: "plugin_hook_one", priority: 1, status: :started}}, 5000)
** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
We should do like this:
test "gets results from GenServer" do
{:ok, pid} = MyAppServer.start_link()
Ecto.Adapters.SQL.Sandbox.allow(Repo, self(), pid)
assert MyAppServer.get_my_data_fast(timeout: 1000) == [...]
end
But it did not speck about a Genserver with dynamic supervisor, for example:
Enum.map(@depends, fn item ->
Map.merge(@new_soft_plugin, %{name: item, depend_type: :hard, depends: List.delete(@depends, item)})
|> MishkaInstaller.PluginState.push_call()
end)
In the top code I pushed 4 items of a list to Genserver and the Genserver pushed it to my database, and each Genserver has the own dynamic supervisor and PID.
After pushing the items to my database, I try to work with their state and call them, but sometimes my Genserver which is supervised dynamically is dropped.
I increase queue_target
and pool_size
, they fix some errors not all the problems
pool_size: 30,
queue_target: 10000,
I have read many topics, but I still have problems with dynamic supervisor Genserver testing, unfortunately.
Thank you.
More code:
def push_call(%PluginState{} = element) do
case PSupervisor.start_job(%{id: element.name, type: element.event}) do
{:ok, status, pid} ->
if Mix.env() == :test, do: Logger.warn("Plugin State of #{element.name} is being pushed")
GenServer.call(pid, {:push, status, element})
{:error, result} -> {:error, :push, result}
end
end
and start job function
def start_job(args) do
DynamicSupervisor.start_child(PluginStateOtpRunner, {MishkaInstaller.PluginState, args})
|> case do
{:ok, pid} -> {:ok, :add, pid}
{:ok, pid, _any} -> {:ok, :add, pid}
{:error, {:already_started, pid}} -> {:ok, :edit, pid}
{:error, result} -> {:error, result}
end
end