You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This allows different databases to be used in dev and test. However:
in some cases, like unit tests, it may be more desirable to stub/mock out the Electric calls
using a long running external DB for Electric may not be compatible (a) a Postgres sandbox or (b) mix ecto.reset
With the Postgres sandbox, using Ecto.Adapters.SQL.Sandbox, operations are wrapped in an outer transaction. This means that Electric never sees the events, because they're not put on the external logical replication stream. This is a bit of a non-starter.
With ecto.reset, wiping a Postgres DB needs to also wipe Electric. The developer will get into issues. We know the ins and outs of this, so we should prescribe a pattern and if necessary provide helpers. The implementation of this may be affected by the mechanism of embedding Electric (because it affects how much control we have over the shape storage etc).
The text was updated successfully, but these errors were encountered:
we can run Electric in ephemeral (storage in memory) mode
we can provide a mix task to add into your ecto.reset list that wipes electric when you wipe the DB
we can maybe provide a setup/teardown helper to wipe shapes before and after tests / test suites
the simplest approach for unit test support is to document how to use the client mock to emit events that you're expecting
a more advanced/complex route is to somehow auto-intercept writes and generate stream events automatically (short cutting logical replication which won't run bc of the sandbox transaction wrapper)
one of the tweaks is to configure Electric to always use a unique shape for each test, which in async mode means maybe having a mode where the lookup of shape handle from definition always fails; so that way concurrent tests can use the same shape definition without re-using shapes
we would also want a way for Electric to use a sandboxed conn in test, so that new shapes can be created that can read the data inserted within the sandbox transaction (for queries to power initial data sync)
At the moment, testing an app that uses
electric_stream
(or any Electric.Client requests) makes requests to an external Electric service.The URL is configurable in the Electric.Client config:
This allows different databases to be used in dev and test. However:
With the Postgres sandbox, using
Ecto.Adapters.SQL.Sandbox
, operations are wrapped in an outer transaction. This means that Electric never sees the events, because they're not put on the external logical replication stream. This is a bit of a non-starter.With
ecto.reset
, wiping a Postgres DB needs to also wipe Electric. The developer will get into issues. We know the ins and outs of this, so we should prescribe a pattern and if necessary provide helpers. The implementation of this may be affected by the mechanism of embedding Electric (because it affects how much control we have over the shape storage etc).The text was updated successfully, but these errors were encountered: