sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Feature request: `flavor = "multi_thread"` support for `#[sqlx::test]`

Open vikanezrimaya opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. From documentation:

#[sqlx::test] does not recognize any of the control arguments supported by #[tokio::test] as that would have complicated the implementation. If your use case requires any of those, feel free to open an issue.

Thus this issue.

Describe the solution you'd like

#[sqlx::test(tokio_flavor = "multi_thread", tokio_threads = 1)]

Describe alternatives you've considered

  • Reimplementing #[sqlx::test] manually in my project without a macro
    • Tedious
  • A second macro that would spawn a multi-threaded runtime
  • ~~Having #[sqlx::test] not spawn a runtime for non-async functions~~ May not be feasible due to how the macro is structured
    • This would allow me to bring my own #[tokio::test] invocation, since the Tokio macros de-asyncifiy the functions they're used on.
  • Just spawn a multi-threaded runtime by default

Additional context n/a

vikanezrimaya avatar Sep 18 '24 21:09 vikanezrimaya

I'd accept a PR to support this:

#[sqlx::test(tokio(...))]

and then we don't have to parse ..., we can just pass it directly to #[tokio::test(...)].

The problem is, that's not currently how it works internally (it expands to more than just #[tokio::test]), so we'd need to move some stuff around.

abonander avatar Sep 20 '24 06:09 abonander

Hello! Is it possible to enable several threads in an sqlx::test?

folex avatar Jan 23 '25 11:01 folex

I'd accept a PR to support this:

#[sqlx::test(tokio(...))]

This would be super helpful! I'd like to combine #[sqlx::test] with #[tokio::test(start_paused = true)]

Jasha10 avatar Aug 13 '25 03:08 Jasha10