/ ruby

Testing app for limited database connection

Recently I was developing a Ruby app where I introduced a nasty bug. Each time someone made a request a new database connection was created and after some time the app crashed because the database couldn't handle so many connections.

I fixed the bug and wanted to test if it is really fixed. My first thought was to gather a group of beta testers and ask them to open the page and leave it opened for a while. It would be sufficient because the app was pulling the data from the server every 60 seconds (this is how I learned about the bug for the first time) but I was reluctant to show the app again to the public before I tested if the bug was actually fixed.

Ruby came to the help. After a tip from a colleague to use curl or wget to test it I wrote a simple script to do it.
The code isn't very object oriented but it serves its purpose.

addresses_with_sessions = [
	<5 localhost addresses with sessions appended to the url>

index = 0
100.times.each_with_index do |i|
  puts "Proces #{i} started"
  fork do
    while index < 100
      `wget -qO- #{addresses_with_sessions.sample}`
      sleep 5
      index += 1
      puts "Process #{i} had #{index} runs"


What it does is creates 100 processes where each hits the application 100 times (10 000 requests in total). That's it.

This test showed that the application did not crash anymore but I still wasn't sure if it was a fix that made the test pass or if the test was poorly designed. I reverted the bug fix and run the test again. The application crashed the way it did before the fix. That meant the the wget test was a good test and that the bug fix actually fixed the problem.

Testing app for limited database connection
Share this