In my rails app, Signup Class has below functions,
def register_email
# Something...
add_to_other_thread do
send_verification_email
end
end
def add_to_other_thread(&block)
Thread.new do
yield
ActiveRecord::Base.connection.close
end
end
And I want to do 3 tests with these.
How to Perform Thread Testing? Thread testing is conducted at the initial phase of the system integration testing process. For this, you need to accurately plan how to put modules in the correct order to integrate them into a complete system. Big-bang approach − All modules are integrated into a single step.
We can run all of our tests at once by using the bin/rails test command. Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case.
RAILS_MAX_THREADS is a way to set the number of threads each of your workers will use under the hood. In the example above, the min_threads_count is equal to the max_threads_count , so the number of threads is constant.
1 Automatic ConcurrencyRails automatically allows various operations to be performed at the same time. When using a threaded web server, such as the default Puma, multiple HTTP requests will be served simultaneously, with each request provided its own controller instance.
Make Thread.new just execute the block instead of doing Thready things. Either stub Thread.new or Mock Thread or replace it.
expect(Thread).to receive(:new).and_yield
See also testing threaded code in ruby
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With