lipanski / mockito

HTTP mocking for Rust!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deadlock creating 2 times the same mock in dev mode

Guara92 opened this issue · comments

Hi,

I'm trying to use mockito for development purposes other than tests, and I'm facing an issuing using mockito in this way.
We have a web service based on actix and juniper, when a graphql request is handled the service will call another service.
I'm trying to mock this external calls but, the first request is correctly mocked, the following request never returns from the Mock::create() function.

fn fetch_data()->Result<Data>{
    #[cfg(feature = "dev")]
    let _mock =  mockito::mock("GET", "/data").with_status(200).with_body("data").create()

   execute_request()
   // tried even to manually drop or reset the mock here, nothing changed
}

Is possible to use mockito this way?

@Guara92 is the mock created from within a thread by any chance?

@lipanski Yes, actix spawn different threads.

@Guara92 unfortunately that is not supported in Mockito. you have to create your mocks from within the main thread. you can still run your application from threads but the mocks have to be created from the main thread, otherwise you experience this locking behaviour. this is documented here and the reason is explained here.