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

Test failing at ProjectCacheImplTest isProjectCacheExpired #5

Open
ninad458 opened this issue Jun 30, 2018 · 7 comments
Open

Test failing at ProjectCacheImplTest isProjectCacheExpired #5

ninad458 opened this issue Jun 30, 2018 · 7 comments

Comments

@ninad458
Copy link

java.lang.AssertionError: Expected: false (class: Boolean), Actual: [] (latch = 1, values = 0, errors = 0, 
completions = 0)

at io.reactivex.observers.BaseTestConsumer.fail(BaseTestConsumer.java:162)
at io.reactivex.observers.BaseTestConsumer.assertValue(BaseTestConsumer.java:327)
at com.nygma.cache.ProjectsCacheImplTest.isProjectsCacheExpiredReturnsNotExpired(ProjectsCacheImplTest.kt:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:497)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:228)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:110)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:37)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:64)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
@AlanUeyn
Copy link

Same error...
What could be wrong?

@jeanPokou
Copy link

jeanPokou commented Nov 5, 2018

I am facing the same issue too

@hitherejoe
Copy link
Owner

hitherejoe commented Nov 13, 2018

The following will fix this:

@Test
fun isProjectsCacheExpiredReturnsNotExpired() {
    cache.setLastCacheTime(System.currentTimeMillis() - 1000).test()
    val testObserver = cache.isProjectsCacheExpired().test()
    testObserver.assertValue(false)
}

Sorry about that, I was using the incorrect value for the cache check. Here we now:

  • Save the current time (minus 1000) as the last cache time
  • Check whether the cache has expired using currentTime - it.lastCacheTime > expirationTime

Here, previously lastCacheTime was 1000 which meant the incorrect value was always being used in the calculation. @jeanPokou @AlanUeyn @ninad458 does this work for you here?

@jeanPokou
Copy link

Thanks, @hitherejoe It is working now

@graffiti75
Copy link

Hello Joe.

It remains with error for the test of test method isProjectsCacheExpiredReturnsNotExpired:

"/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java" -ea -Didea.test.cyclic.buffer.size=1048576 -Didea.launcher.port=50193 ...
WARNING: No manifest file found at ./AndroidManifest.xml.
Falling back to the Android OS resources only.
To remove this warning, annotate your test class with @Config(manifest=Config.NONE).
java.lang.AssertionError: Expected: false (class: Boolean), Actual: 

at io.reactivex.observers.BaseTestConsumer.fail(BaseTestConsumer.java:162)
at io.reactivex.observers.BaseTestConsumer.assertValue(BaseTestConsumer.java:327)
at br.cericatto.cache.ProjectsCacheImplTest.isProjectsCacheExpiredReturnsNotExpired(ProjectsCacheImplTest.kt:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:497)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:228)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:110)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:37)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:64)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)

Process finished with exit code 255

Also the same error happens for this other test method isProjectsCacheExpiredReturnsExpired.

@jeanPokou
Copy link

jeanPokou commented Nov 21, 2018

Hi, @graffiti75 what version of Robolectric are you using? you should upgrade to 4.0.2. I was finally able to make it work with

    @Test
    fun isProjectCacheReturnsExpired() {
        projectsCacheLocal.setLastCacheTime(1000L).test()
        projectsCacheLocal.isProjectsCacheExpired().test().assertValue(true)
    }
   @Test
    fun isProjectsCacheReturnsNotExpired() {
        projectsCacheLocal.setLastCacheTime(System.currentTimeMillis()).test()
        projectsCacheLocal.isProjectsCacheExpired().test().assertValue(true)
    }

Here is the isProjectsCachedExpired function

   override fun isProjectsCacheExpired(): Single<Boolean> {
        val currentTime = System.currentTimeMillis()
        val expirationInterval =(1000 * 60 * 60 ).toLong() // 1 hour
        return  projectsDataBase.configDao().getConfig()
            .single(
            // if config empty set last cache time to zero
            Config(lastCacheTime = 0)).map {
            currentTime - it.lastCacheTime > expirationInterval
        }
    }

Ps: You may have differents functions names

@graffiti75
Copy link

Robolectric

Version 3.4.2.

I tried updating the Robolectric version, but the same errors persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants