Mockwebserver and OkHttpIdlingResrouce Connect Exception - android

I am writing instrumentation tests using Square's MockWebServer to mock server responses and OkHttpIdlingResource to wait for OkHttp to finish work until the remaining test steps continue. I am also using a MockWebServer dispatcher so that I can respond to certain requests differently depending on the path.
I am running into an issue where the tests work for some Android API versions and they don't work for others.
On Marshmallow the tests pass as expected. When I run on Android Pie, the MockWebServer responds to several requests, but then, for some reason, OkHttp throws a java.net.ConnectException.
If I hit my real web server everything works fine for any app version, it's only when using MockWebServer that I see this issue.
I have no idea what would cause this and the logs are not surfacing anything useful. In the failure case I can see that the MockWebServer has several successful 200 responses, but for some reason a ConnectException occurs during one of the calls.
The only weird thing I can see in the logs is that an Espresso ViewAssertion is logged before the last, failing, OkHttp request is logged. So it may be that the OkHttpIdlingResource is saying that it is idle when it really isn't.
Any ideas on what could be wrong?

Related

Detox Test device.disableSynchronization() works on iOS but not android

My test suite runs fine on iOS, the app has many background processes running that prevent large portions of the tests from working in synchronized mode. The desynced commands run properly on the iOS simulator, but when I run them on the android emulator it is as if I never called await device.disableSynchronization().
The tests still hang and the console logs:
The app is busy, due to:
- Enqueued timers
- Animations running on screen
Any ideas about how to fix this?
Further review shows the error message:
The app has not responded to the network requests below:
The odd thing is the listed network request has been completed. The request upon which the app purportedly has not responded is a button push that navigates to a new screen which incurs a somewhat lengthy network request. After the network request completes other processes continually run necessitating the disabled synchronization. Since Detox is still waiting on some response from the app about the button tap, it does not move on to the next, desynchronized, actions. Is there any way to ensure that Detox receives the response of this .tap()?
A deeper investigation reveals that this is likely caused by a lingering animation that, for whatever reason device.disablesynchronization() ignores on Android builds. I am now working on mocking this file based on the out-of-date documentation provided by wix.

Retrofit ignores some requests

I have an android app with server communication layer, implemented with Retrofit 2. It sends requests with .enqueue method. All API methods works fine, except one. In this case after calling .enqueue nothing happents. And i mean it) No exceptions, no messages in logcat. Just silence. Maybe some1 faced with dimilar situation?

Firebase test lab showing unexpected test failures

I've started using Firebase Test Lab recently with espresso. All the test cases pass on my local device but when it comes to testing devices present on google cloud, some test cases fail with exceptions like "NoMatchingViewException". I've tried increasing the wait time before the test runs and the fragment loads, but that too does not seem to help. Please help if you know how to resolve this issue. Thank you!
I had the same problem when I tried my app. The problem is that I used UDPSocket in my application.. kinda weird but there was this exception thrown : NoMatchingViewException.
So, I Mocked the UDP call. So at least I was able to do the UI automated test.

Okhttp 3.4.1 inconsistent with throwing IOException?

I'm seeing this really bizarre issue with okhttp. I am using okhttp to upload files to the server via post streaming. It's the same code as in okhttp recipes for post streaming:
while ((count = source.read(buffer)) != -1) {
sink.write(buffer, 0, count);
}
This works fine. The loop is inside writeTo method, which is part of the RequestBody - all like in the recipe. The body is wrapped into try/catch block and on IOException I fail my upload task and move on. This worked perfectly with okhttp 3.0.1.
I've now updated to okhttp 3.4.1 and I'm getting a really weird and inconsistent behavior. I'm testing with switching on the airplane mode mid upload and expecting to get IOException to fail the upload, but sometimes I'm getting it and sometimes not. I can't really figure out what this behavior is connected with. Just killing the app and repeating the test case will throw the expected exception once every 5 times or so.
Wondering if anyone else has seen similar behaviour and if there are any workaround apart from downgrading back to 3.0.1?
EDIT:
It looks like there are several exceptions that are all extending IOExceptions but not all of them make it out of the okhttp land.
These two are never reaching my try/catch block:
java.io.IOException: closed
at okhttp3.internal.framed.Http2$Writer.data(Http2.java:482)
at okhttp3.internal.framed.FramedConnection.writeData(FramedConnection.java:332)
at okhttp3.internal.framed.FramedStream$FramedDataSink.emitDataFrame(FramedStream.java:516)
at okhttp3.internal.framed.FramedStream$FramedDataSink.write(FramedStream.java:489)
at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
at okio.RealBufferedSink.write(RealBufferedSink.java:96)
at okio.RealBufferedSink.write(RealBufferedSink.java:96)
javax.net.ssl.SSLException: Write error: ssl=0x9bad4480: I/O error during system call, Connection timed out
at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:771)
at okio.Okio$1.write(Okio.java:78)
at okio.AsyncTimeout$1.write(AsyncTimeout.java:180)
at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:171)
at okio.RealBufferedSink.write(RealBufferedSink.java:41)
at okhttp3.internal.framed.Http2$Writer.dataFrame(Http2.java:494)
at okhttp3.internal.framed.Http2$Writer.data(Http2.java:487)
at okhttp3.internal.framed.FramedConnection.writeData(FramedConnection.java:311)
at okhttp3.internal.framed.FramedStream$FramedDataSink.emitDataFrame(FramedStream.java:515)
at okhttp3.internal.framed.FramedStream$FramedDataSink.write(FramedStream.java:488)
at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:171)
at okio.RealBufferedSink.write(RealBufferedSink.java:91)
However, this one seems to be getting all the way to my try/catch block:
okhttp3.internal.framed.StreamResetException: stream was reset: CANCEL
at okhttp3.internal.framed.FramedStream.checkOutNotClosed(FramedStream.java:574)
at okhttp3.internal.framed.FramedStream.access$1200(FramedStream.java:34)
at okhttp3.internal.framed.FramedStream$FramedDataSink.emitDataFrame(FramedStream.java:508)
at okhttp3.internal.framed.FramedStream$FramedDataSink.write(FramedStream.java:488)
at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:171)
at okio.RealBufferedSink.write(RealBufferedSink.java:91)
I have a feeling this might be something to do with my okhttp client being set to retryOnConnectionFailure(true), but if that is the case, why a total loss of connectivity (airplane mode) is considered a recoverable failure?
EDIT 2:
Did some testing with retryOnConnectionFailure(false) and all of the above exceptions are now making it to my try/catch block. Also added an interceptor (network) and set retryOnConnectionFailure(true), repeated the test and noticed that okhttp goes into an endless loop of sending out requests to my server. Bug or a feature and I'm not using it correctly? Really confused with this behaviour..

loopj multiple async requests not returning in signed APK

I have an app that requires a lot of async requests, for which I am using the loopj asynchttpclient library.
After login to a service, many requests get made, someone loading 5-10 images at one time, and a couple JSON requests, all made around the same time. I never had an issue in all of my debug testing over the last several months. But after building a signed APK and installing, when multiple requests get ran simultaneously (in the above description) - the requests stop returning anything. None of the call backs are called. The server is receiving the requests and returning, but the async http callbacks never get called.
I have read that if all the callbacks are not implemented its possible they won't call, but I have implemented them all including the deprecated ones and still no luck.
Any reason why this would happen? I am kind of late in the game and am trying to avoid having to switch to an entirely different networking library.
Cheers

Categories

Resources