-
Cache being standalone GenServer, can be tested in isolation
-
add test helper function to assist clean shutdown of GenServer & handle errors like timeout
tests at
cache_test.exs
- add
TestBackendstub, use it to check for results with items, empty, timeout & crash
Stubs wouldn't fail tests acting as checks, just providing replacement behavior.
Mocks replace real behavior as stub but also allow specifying expectation & results to be played at runtime.. failing a test if expectations don't meet.
-
dynamic mocks are avoided, replacement at global create issues for tests running concurrently
-
better way is to make difficult to live test code provider configurable, give replaceable testing implementation
making our HTTP service pluggable; with
:httpcused in dev/prod & test client module for testing
# at wolfram.ex
@http_client Application.get_env(:nfo, :wolfram)[:http_client] || :httpc
...
|> @http_client.request()
...
# at test.ex config
config :nfo, :wolfram,
app_id: "testx",
http_client: Nfo.Test.HTTPClient
- Bypass https://github.com/PSPDFKit-labs/bypass, can be used similar to Go HTTPTest strategy... creating a custom plug to place instead of actual HTTP server to return prebaked responses
- underneath Channels are OTP servers; Phoenix provides
Phoenix.ChannelTestmodule to simplify testing
apps/videologue_web/test/support/channel_case.exwas generated by Mix initially providingVideologueWeb.ChannelCaseto beuse/injected as foundation in channel tests
- VideologueWeb just has one channel
VideoChannel; before testing it test where channel process begins..UserSocketmodule
test
connectwith signed token & fake tokens to work as desired
add a supprt script
test_data.exsable toinsert_user,insert_video&login
-
assert_replyensures:ok/..response; can pass a map to assert on specific fields -
assert_broadcastmake sure ur annotation were broadcast to subscribers -
assert_reply&assert_broadcastare built on top ofassert_receive -
for
new annotation triggers Nfo, addwolframuser as a backend-user will be used to broadcast reply bycompute_additional_info
- receiving error like
05:58:50.326 [error] Task #PID<0.682.0> started from VideologueWeb.Presence_shard0 terminating
** (stop) exited in: DBConnection.Holder.checkout(#PID<0.679.0>, [log: #Function<14.39275128/1 in Ecto.Adapters.SQL.with_log/3>, source: "users", timeout: 15000, pool_size: 10, pool: DBConnection.Ownership])
** (EXIT) shutdown: "owner #PID<0.678.0> exited"
(db_connection 2.4.0) lib/db_connection/holder.ex:95: DBConnection.Holder.checkout/3
...
use Jose Valim's fix
or just mine test dummy implementation from Videologue Umbrella