gavares

gavares

I’m trying to use Commanded with Phoenix to create an eventsourced application. I’ve pieced things together from the conduit repo and the commanded docs but I’m getting a failure and stacktrace when I try to run my tests against my aggregate.

There is quite a bit of configuration, support code, and application code so I’m not sure which of that would be helpful to post here. Once my tests start, I’m getting error message:

** (UndefinedFunctionError) function Ecto.Adapters.SQL.Sandbox.child_spec/1 is undefined or private
     stacktrace:
       Ecto.Adapters.SQL.Sandbox.child_spec({Postgrex.Protocol, [types: Postgrex.DefaultTypes, username: "postgres", password: "password", database: "accounts_test", hostname: "localhost", pool: Ecto.Adapters.SQL.Sandbox, pool_size: 2]})
       (db_connection) lib/db_connection.ex:389: DBConnection.start_link/2
       (accounts) test/support/storage.ex:24: Accounts.Storage.reset_readstore/0
       (accounts) test/support/storage.ex:7: Accounts.Storage.reset!/0
       (ex_unit) lib/ex_unit/on_exit_handler.ex:142: ExUnit.OnExitHandler.exec_callback/1
       (ex_unit) lib/ex_unit/on_exit_handler.ex:128: ExUnit.OnExitHandler.on_exit_runner_loop/0

I’ve looked at db_connection.ex:389 and it’s not calling child_spec/1 so I’m very confused why this is happening. I’ve been trying to debug this for about 4 hours now and I’m at a loss.

The last bit of my code from the stacktrace above:

  defp reset_readstore do
    config = Application.get_env(:accounts, Accounts.Repo)
    {:ok, conn} = Postgrex.start_link(config)

    Postgrex.query!(conn, truncate_readstore_tables(), [])
  end

Showing Posts 1 to 10

gcauchon

gcauchon

I don’t think you can simply respawn Postgrex under your application supervision tree like you are trying to.

The postgres adapter is managed by Ecto.Adapters.Postgresl (ecto_sql), which is supervised by Ecto.Repo (ecto), which is supervised by you application.

And there is fair amount of config involved to setup the Ecto.Adapters.SQL.Sandbox adapter defined in config/test.exs when running tests.

gavares

gavares OP

The place where I call reset_readstore is in my data_case.ex file and I stop everything just before I call reset_readstore:

  using do
    quote do
      alias Accounts.Repo

      import Ecto
      import Ecto.Changeset
      import Ecto.Query
      # import Accounts.Factory
      # import Accounts.DataCase
      import Commanded.Assertions.EventAssertions
    end
  end

  setup do
    {:ok, _} = Application.ensure_all_started(:accounts)
    
    on_exit(fn ->
      :ok = Application.stop(:accounts)
      :ok = Application.stop(:commanded)
      :ok = Application.stop(:eventstore)
      Accounts.Storage.reset_readstore()
    end)

    :ok
  end

So my understanding is that everything is shutdown by data_case.ex and then I have to re-open the store in order to cleanup the database tables.

axelson

axelson

Scenic Core Team

Is there a particular reason you’re trying to cleanup the database tables yourself? The Ecto Sandbox is able to take of that for you (by running tests each in their own transaction, either sync or async). If you relied on the Sandbox to do the cleanup than you should be able to remove a bunch of your test configuration/setup.

gavares

gavares OP

Thanks @axelson, that’s really helpful. The cleanup code I have is taken from the commanded docs and I found similar code in the conduit repo that I am basing my app off of. If Sandbox can handle that logic for me, so much the better. I’ll give that a try.

gavares

gavares OP

@axelson, thanks for the help. Removing my manual cleanup code solved my problem.

axelson

axelson

Scenic Core Team

I’m glad you got it working! I wonder if it would make sense to submit a PR for that portion of the commanded docs. My guess is that commanded is trying to be database adapter agnostic, but at least a mention of the Ecto Sandbox would probably fit in that section.

gavares

gavares OP

@axelson, I had the same thought. I’ll submit something to update the docs. One thing I’ve noticed, setting the pool to Sandbox for eventstore still seems to leave events in the database after my tests complete and seems to be causing some of my tests to fail since the state isn’t getting properly reset between test runs.

I wonder if EventStore doesn’t work properly with Sandbox.

LostKobrakai

LostKobrakai

EventStore doesn’t use ecto and therefore cannot be controlled using the ecto sandbox. It uses postgrex directly and therefore needs manual action for cleanup.

sahina

sahina

@LostKobrakai commanded is v1.0 now but all the example application i see like are using older version of commanded. do you know a sample v1.0 commanded project?

These are pre 1.0

https://github.com/slashdotdash/segment-challenge

Thanks

slashdotdash

slashdotdash

The GitHub repo for the “Building Conduit” eBook has been updated to use Commanded and EventStore v1.0 if you are still looking.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews