Hi,
I'm trying to run tests in an Actix application, some of the tests are just "normal" test, declared with the #[test]
macro, and some others are async tests declared with #[tokio::test]
.
Some of the tests are doing operations with files and directories, creation, deletion etc, so everything must be run on 1 thread.
In previous projects (with actix 3.*
)I had no problem running similar tests just specifying in the CLI argument cargo test -- --test-threads 1
. But now in this project I'm using actix 4
and things seem to be different:
As soon as some tokio::test
tests are declared, the --test-threads
argument is causing an error like invalid or unexpected argument --test-threads
.
Not only --test-threads
but any argument from CLI (I can't name a test to run, nor ignore one, etc...) is failing as soon as a tokio::test
is declared somewhere.
So I tried to declare all my tests as tokio tests :
#[tokio::test]
async fn mytest() {}
thinking that it might be some conflict between the regular test runner and the tokio runtime.
My tests are run but they fail because of concurrency issues, the io
operations are not synchronized so the tests fail. That's what happens when the test are run on more than 1 thread.
So I tried to specify explicitly that I want only one thread running (despite the Tokio docs says that default is single threaded)
#[tokio::test(flavor="current_thread")]
async fn mytest() {}
or even
#[tokio::test(flavor="multi_thread", worker_threads=1)]
async fn mytest() {}
But nothing works, the tests keep randomly failing for the same reasons and I can't get the tests being run synchronously on one thread. And again I never had this problem with previous versions of Actix.
I didn't create an issue about this on Github because I'm not sure about whats going wrong, I might just have misunderstood something ...
Thank you for any help !