How can I write integration tests for eio code, with real i/o?

I’ve written some caqti_eio code, and I’d like to write some integration tests against a postgres db. I’d like to use alcotest or another test framework, not just an ad-hoc script, and I’d like to create a DB connection as a suite-level fixture that the tests reuse. I assume the test runner needs to provide support for eio in the way it might support a test that returns an Lwt.t. Is there such a testing library?

Or is the solution to just call Eio_main.run in each test? In which case how might I create a suite-level fixture of a db connection?

The test suite has a single entry point. You can start the Eio loop, connect to the DB, then pass the connection to any tests that need it, from there. Eg

let () =
  Eio_main.run (fun env ->
    let conn = ... in

    Alcotest.run "My suite" [
      test_foo conn;
      test_bar conn;
    ])
1 Like