Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require File.join(File.dirname(__FILE__), 'CONFIG.rb')
- require 'rubygems'
- require 'facets'
- require 'test/unit'
- require 'og'
- class TCOgManager < Test::Unit::TestCase # :nodoc: all
- include Og
- class User
- attr_accessor :name, String
- end
- $og1.manage_classes(User)
- def setup
- 10.times {User.create}
- end
- # Query Og via 'infinite' threads.
- # This is heavily bias towards SQLite and probably won't fail with other
- # adapters.
- # If the connection pool is not managed correctly then you may:
- # 1. You will leak file descriptors/memory.
- # 2. Block due to incorrect semaphore coordination.
- #
- # I assume you're running with a standard 1024 maximum Linux file descriptor.
- def test_connection_pool
- #number of threads to run concurrently.
- max_threads = 1500
- #maximum length test should run for.
- timeout = 60
- #poll threads every n seconds
- poll = 5
- Thread.abort_on_exception = true
- completed = 0
- max_threads.times do
- Thread.new(completed) do |c|
- User[1]
- completed +=1
- end
- end
- #Sleep until exception occurs or 1500 threads have completed.
- #If they completed then the test passes!
- slept = 0
- until completed == max_threads or slept >= timeout
- sleep(poll)
- slept += poll
- end
- assert slept < timeout
- #Probably a good time to clean up.
- GC.start
- end
- end
Add Comment
Please, Sign In to add comment