Search code examples
ruby-on-railsherokuthread-safetypuma

Testing for Threat Safety in Rails


Now that Puma is the recommended web server for Rails on Heroku, they are warning of the dangers of using non-threadsafe code.

How do you test a Rails app for thread safety?


Solution

  • You generally test thread safety by assigning and verifying the value of a variable. In a rspec:

    • fork 2 processes
    • first process would assign the variable with a value
    • first process would pause for a second
    • second process would assign the same variable with a different value

    Expected: both variable have different values