test(support): add resp client and server test helpers
This commit is contained in:
1 parent
73e4c917d0
commit
5de6afbb61
3 files changed
+122
No files matched your search
@@ -0,0 +1,37 @@
|
||||
defmodule Excache.Test.ServerCase do
|
||||
@moduledoc false
|
||||
|
||||
use ExUnit.CaseTemplate
|
||||
|
||||
using do
|
||||
quote do
|
||||
alias Excache.Test.RespClient, as: Client
|
||||
end
|
||||
end
|
||||
|
||||
setup do
|
||||
snapshot = Path.join(File.cwd!(), "tmp/snapshot_#{System.unique_integer([:positive])}.bin")
|
||||
aof = Path.join(File.cwd!(), "tmp/aof_#{System.unique_integer([:positive])}.bin")
|
||||
|
||||
Application.put_env(:excache, :snapshot_path, snapshot)
|
||||
Application.put_env(:excache, :aof_path, aof)
|
||||
Excache.Store.flushdb()
|
||||
Excache.Aof.restart()
|
||||
|
||||
{:ok, acceptor} = Excache.Server.Acceptor.start_link(port: 0)
|
||||
port = Excache.Server.Acceptor.port(acceptor)
|
||||
conn = Excache.Test.RespClient.connect(port)
|
||||
|
||||
on_exit(fn ->
|
||||
Excache.Test.RespClient.close(conn)
|
||||
if Process.alive?(acceptor), do: GenServer.stop(acceptor)
|
||||
File.rm(snapshot)
|
||||
File.rm(aof)
|
||||
Excache.Store.flushdb()
|
||||
Application.delete_env(:excache, :snapshot_path)
|
||||
Application.delete_env(:excache, :aof_path)
|
||||
end)
|
||||
|
||||
%{conn: conn, port: port}
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user