Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simultaneous queries can lead to the wrong responses #25

Closed
JuBan1 opened this issue Mar 18, 2020 · 1 comment · Fixed by #27
Closed

Simultaneous queries can lead to the wrong responses #25

JuBan1 opened this issue Mar 18, 2020 · 1 comment · Fixed by #27
Assignees
Labels
bug Something isn't working
Milestone

Comments

@JuBan1
Copy link

JuBan1 commented Mar 18, 2020

Describe the bug
I have two API-Endpoints, getA() and getB() which return ResultA and ResultB respectively. Both are mocked using Mockinizer. Both Endpoints are queried at the same time. In a good number of cases the getA() query will end up getting the ResultB response, and vice versa.

My guess is that both results are intercepted by Mockinizer, the responses are enqueued into MockServer, but MockServer handles the two responses in the opposide order, leading to the wrong response being given out.

I've verified that retrofit actually receives the wrong response by logging to json body of for the two endpoints.

To Reproduce
Very simply put, I have this set-up.

interface TestInterface {
    @GET("/v1/a")
    suspend fun getA(): Response<ResultA>
    @GET("/v1/b")
    suspend fun getB(): Response<ResultB>
}
class Repository {
    fun loadA() {
        GlobalScope.launch {
            val resultA = retrofit.createInterface(...).getA() // sometimes fails because my mock response for getB can't be converted to ResultA
        }
    }
    fun loadB() {
        GlobalScope.launch {
            val resultB = retrofit.createInterface(...).getB() // sometimes fails because my mock response for getA can't be converted to ResultB
        }
    }
}
fun someFunction() {
    repository.loadA()
    repository.loadB()
}

At the moment I'm trying to understand the issue and figure out if I'm misusing something or if Mockinizer+MockServer is the culprit. I'll see if I can create a minimal test sample to showcase the problem.

In the meantime, I thought I'd ask whether you've seen issues like that previously.

PS: Perhaps to add, in the past I've used this method to handle giving out mock responses, rather than enqueue. Maybe that's a good way to go.

@JuBan1 JuBan1 added the bug Something isn't working label Mar 18, 2020
@donfuxx
Copy link
Owner

donfuxx commented Mar 21, 2020

Hi @JuBan1 parallel mocking of api responses isn't something that I have tested yet with Mockinizer. Your assumption that dispatch instead enqueue might be better for that case seem to be correct to me. I'll try that out.
Thanks for your investigation efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants