Coder Social home page Coder Social logo

Comments (4)

technoir42 avatar technoir42 commented on August 28, 2024 1

I'm having a crash in DelegatingIdlingResourceScheduler.stopWork as well due to callback being null.

from rxidler.

kenyee avatar kenyee commented on August 28, 2024

Related to this, we get a similar crash by trying to do the init "(RxJavaPlugins.setInitIoSchedulerHandler(Rx2Idler.create(RXJAVA_IO_SCHEDULER_NAME))" in TestRunner's onCreate (otherwise, the app init creates schedulers before onStart so it will never get overridden w/ the idling one). If we do the init in onStart, the IOScheduler is already started so InitIoSchedulerHandler never gets called (verified w/ breakpoints)

from rxidler.

kenyee avatar kenyee commented on August 28, 2024

DelegatingIdlingResourceScheduler.stopWork() probably needs a null check for callback but it also looks like it's not initialized properly...

from rxidler.

danieldello avatar danieldello commented on August 28, 2024

I've written a workaround for this error while the issue is not merged, it's far from perfect but it does the trick for me.

class TestRunner : AndroidJUnitRunner() {

    override fun onStart() {
        RxJavaPlugins.setInitComputationSchedulerHandler {
            Rx2Idler.create("RxJava Computation Scheduler").apply(it).also {
                forceIdlingResourceRegistrySync()
            }
        }
        RxJavaPlugins.setInitIoSchedulerHandler {
            Rx2Idler.create("RxJava IO Scheduler").apply(it).also {
                forceIdlingResourceRegistrySync()
            }
        }
        super.onStart()
    }

    @Suppress("DEPRECATION")
    private fun forceIdlingResourceRegistrySync() {
        // Workaround for https://github.com/square/RxIdler/issues/20
        // This forces espresso to sync idling resources, cause the callback to be set for all available
        // resources and preventing RxIdler from crashing
        // By registering and unregistering a new resource we will force the registry to be updated,
        // we don't really care for the resource we are registering itself
        // TODO PLEASE REMOVE THIS ONCE THE BUG ON RXIDLER HAS BEEN FIXED
        val mockIdlingResource = object : IdlingResource {
            override fun getName(): String = "Mock Idling Resource Name"

            override fun isIdleNow(): Boolean = false

            override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) {
            }
        }
        Espresso.registerIdlingResources(mockIdlingResource)
        Espresso.unregisterIdlingResources(mockIdlingResource)
    }
}

I'm not sure if a simple call to Espresso.onIdle would suffice, and since I can't seem to reproduce it consistently I went with a flow that I could easily track. If there's a cleaner way to do this please let me know

from rxidler.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.