{"action":"created","issue":{"url":"https://api.github.com/repos/robolectric/robolectric/issues/2534","repository_url":"https://api.github.com/repos/robolectric/robolectric","labels_url":"https://api.github.com/repos/robolectric/robolectric/issues/2534/labels{/name}","comments_url":"https://api.github.com/repos/robolectric/robolectric/issues/2534/comments","events_url":"https://api.github.com/repos/robolectric/robolectric/issues/2534/events","html_url":"https://github.com/robolectric/robolectric/issues/2534","id":162644043,"number":2534,"title":"RxJava. subscribeOn, observeOn issue?","user":{"login":"cvoronin","id":2241595,"avatar_url":"https://avatars.githubusercontent.com/u/2241595?v=3","gravatar_id":"","url":"https://api.github.com/users/cvoronin","html_url":"https://github.com/cvoronin","followers_url":"https://api.github.com/users/cvoronin/followers","following_url":"https://api.github.com/users/cvoronin/following{/other_user}","gists_url":"https://api.github.com/users/cvoronin/gists{/gist_id}","starred_url":"https://api.github.com/users/cvoronin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cvoronin/subscriptions","organizations_url":"https://api.github.com/users/cvoronin/orgs","repos_url":"https://api.github.com/users/cvoronin/repos","events_url":"https://api.github.com/users/cvoronin/events{/privacy}","received_events_url":"https://api.github.com/users/cvoronin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-06-28T09:41:39Z","updated_at":"2016-06-28T13:09:40Z","closed_at":null,"body":"### Description\r\nWhen I use both subscribeOn and observeOn, I see no subscribe's result.\r\n\r\n### Steps to Reproduce\r\n\r\nInitial state: no subscribeOn and no observerOn, works fine\r\n```\r\n@Test\r\nfun testPrint() {\r\n  Observable.just(\"Hi\").subscribe { printValueWithThreadInfo(it) }\r\n}\r\n\r\nHi  : [(1) main/main ]\r\nProcess finished with exit code 0\r\n```\r\n\r\nNow I add subscribeOn:\r\n```\r\nObservable.just(\"Hi\")\r\n  .subscribeOn(Schedulers.computation())\r\n  .subscribe { printValueWithThreadInfo(it) }\r\n\r\nHi  : [(17) main/RxComputationScheduler-1 ]\r\nProcess finished with exit code 0\r\n```\r\nOk. \r\nI remove subscribeOn,add observeOn:\r\n```\r\nObservable.just(\"Hi\")\r\n  .observeOn(AndroidSchedulers.mainThread())\r\n  .subscribe { printValueWithThreadInfo(it) }\r\n\r\nHi  : [(1) main/main ]\r\nProcess finished with exit code 0\r\n```\r\n\r\nGood. And now I add both subscribeOn and observeOn:\r\n\r\n```\r\nObservable.just(\"Hi\")\r\n  .subscribeOn(Schedulers.computation())\r\n  .observeOn(AndroidSchedulers.mainThread())\r\n  .subscribe { printValueWithThreadInfo(it) }\r\n\r\nProcess finished with exit code 0\r\n```\r\n**Ooops**. In this case I see no result.\r\n\r\n### Robolectric & Android Version\r\nrobolectric: _org.robolectric:robolectric:3.1_\r\nandroid sdk: _23_\r\n"},"comment":{"url":"https://api.github.com/repos/robolectric/robolectric/issues/comments/229043674","html_url":"https://github.com/robolectric/robolectric/issues/2534#issuecomment-229043674","issue_url":"https://api.github.com/repos/robolectric/robolectric/issues/2534","id":229043674,"user":{"login":"cvoronin","id":2241595,"avatar_url":"https://avatars.githubusercontent.com/u/2241595?v=3","gravatar_id":"","url":"https://api.github.com/users/cvoronin","html_url":"https://github.com/cvoronin","followers_url":"https://api.github.com/users/cvoronin/followers","following_url":"https://api.github.com/users/cvoronin/following{/other_user}","gists_url":"https://api.github.com/users/cvoronin/gists{/gist_id}","starred_url":"https://api.github.com/users/cvoronin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cvoronin/subscriptions","organizations_url":"https://api.github.com/users/cvoronin/orgs","repos_url":"https://api.github.com/users/cvoronin/repos","events_url":"https://api.github.com/users/cvoronin/events{/privacy}","received_events_url":"https://api.github.com/users/cvoronin/received_events","type":"User","site_admin":false},"created_at":"2016-06-28T13:09:40Z","updated_at":"2016-06-28T13:09:40Z","body":"@karlicoss, \r\nI have seen something, and somthing was null :)\r\n\r\nTo simplify previous example I have removed some syncronization-code, in full version it looks like\r\n```\r\n@Test\r\nfun testPrint() {\r\n  val latch = CountDownLatch(1)\r\n  Observable.just(\"Hi\")\r\n    .subscribeOn(Schedulers.computation())\r\n    .observeOn(AndroidSchedulers.mainThread())\r\n      .subscribe(\r\n        { printValueWithThreadInfo(it) },\r\n        { println(\"Error: ${it.message}\") },\r\n        {\r\n          println(\"OnCompleted\")\r\n          latch.countDown()\r\n        })\r\n\r\n  // Fails with observeOn(AndroidSchedulers.mainThread()), \r\n  // works OK without it\r\n  assertTrue { latch.await(5, TimeUnit.SECONDS) } \r\n}\r\n```\r\nso, I'm afraid, it is not that case.\r\n\r\nThis case seems to be UI thread-related:\r\n\r\n```\r\n    @Test\r\n    fun synchWithUiThread() {\r\n        val latch = CountDownLatch(1)\r\n        async() {\r\n            uiThread {\r\n                latch.countDown()\r\n            }\r\n        }\r\n\r\n        assertTrue { latch.await(2, TimeUnit.SECONDS) } // FAILS\r\n    }\r\n\r\n```\r\n```\r\n    @Test\r\n    fun synchWithoutUiThread() {\r\n        val latch = CountDownLatch(1)\r\n        async() {\r\n            latch.countDown()\r\n        }\r\n\r\n        assertTrue { latch.await(2, TimeUnit.SECONDS) } // OK\r\n    }\r\n```"}}
{"actor":{"display_login":"cvoronin"}}