I was addicted to unit testing with the buffer operator in RxJava

This article is crude.

Conclusion

I had set trampoline in RxJavaPlugins.set *** SchedulerHandler, but only setIoSchedulerHandler.

RxJavaPlugins.setIoSchedulerHandler { Schedulers.trampoline() }

why

I was writing a Test Rule like this,

RxJavaPlugins.setIoSchedulerHandler { Schedulers.trampoline() }
RxJavaPlugins.setComputationSchedulerHandler { Schedulers.trampoline() }
...

If the code under test has a buffer operator, the buffer operator internally uses the computation scheduler, so overwriting the trampoline scheduler will keep waiting indefinitely. The test never ends.

@Test
fun testBuffer() {
    val subject = PublishSubject.create<Int>()
    val testObserver = subject
        .buffer(1, TimeUnit.SECONDS)
        .filter { it.isNotEmpty() }
        .test()

    subject.onNext(1)
    subject.onNext(2)

    testObserver.await(2, TimeUnit.SECONDS)
    testObserver.assertValues(listOf(1, 2))
}

Recommended Posts

I was addicted to unit testing with the buffer operator in RxJava
I was addicted to the NoSuchMethodError in Cloud Endpoints
What I was addicted to with the Redmine REST API
I was addicted to the roll method
I was addicted to the Spring-Batch test
A story I was addicted to with implicit type conversion of ActiveRecord during unit testing
A story I was addicted to when testing the API using MockMVC
Problems I was addicted to when building the digdag environment with docker
I was addicted to doing onActivityResult () with DialogFragment
SpringSecurity I was addicted to trying to log in with a hashed password (solved)
I was addicted to the record of the associated model
The part I was addicted to in "Introduction to Ajax in Java Web Applications" of NetBeans
What I was addicted to when introducing the JNI library
I was addicted to setting default_url_options with Rails devise introduction
I was addicted to looping the Update statement on MyBatis
A story I was addicted to in Rails validation settings
I was addicted to the setting of laradock + VSCode + xdebug
I was addicted to using Java's Stream API in Scala
The story I was addicted to when setting up STS
I was addicted to starting sbt
What I was addicted to when implementing google authentication with rails
About the matter that I was addicted to how to use hashmap
[Java] I want to perform distinct with the key in the object
I was addicted to the API version min23 setting of registerTorchCallback
Technical causes and countermeasures for the points I was addicted to with the first Android app & Kotlin
Memorandum: What I was addicted to when I hit the accounting freee API
[Rails] I was addicted to the nginx settings when using Action Cable.
Recorded because I was addicted to the standard input of the Scanner class
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
I was addicted to scrollview because I couldn't tap the variable size UIView
A story that I was addicted to twice with the automatic startup setting of Tomcat 8 on CentOS 8
I was addicted to using RXTX on Sierra
Assignment to multiple variables with the ternary operator
I tried to organize the session in Rails
I was addicted to installing Ruby/Tk on MacOS
I was addicted to not being able to connect to AWS-S3 from the Docker container
I was a little addicted to the S3 Checksum comparison, so I made a note.
I want to get the value in Ruby
What I was addicted to when developing a Spring Boot application with VS Code
A memo that I was addicted to when making batch processing with Spring Boot
I want to change the path after new registration after logging in with multiple devises.
When I tried to unit test with IntelliJ, I was told "java.lang.OutOfMemoryError: Java heap space"
A memorandum because I was addicted to the setting of the Android project of IntelliJ IDEA
What I was addicted to when trying to properly openAPI/Swagger documentation with Rails + Grape + Grape Swagger
I tried to organize the cases used in programming
I want to embed any TraceId in the log
Tokoro I rewrote in the migration from Wicket 7 to 8
I want to dark mode with the SWT app
Organized how to interact with the JDK in stages
Addicted to the webpacker that comes standard with Rails 6
I tried to implement the Euclidean algorithm in Java
When I tried to scroll automatically with JScrollBar, the event handler was drawn only once.
I want to recreate the contents of assets from scratch in the environment built with capistrano
I was addicted to WSl when trying to build an android application development environment with Vue.js
What I fixed when updating to Spring Boot 1.5.12 ・ What I was addicted to
I want to set the conditions to be displayed in collection_check_boxes
I tried to increase the processing speed with spiritual engineering
Technical causes and countermeasures for the points that I was addicted to with the Android app & Kotlin (2. Processing related to the camera function of Android *)
What I did in the version upgrade from Ruby 2.5.2 to 2.7.1
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I was confused because there was a split in the Array