如何使导轨与活动记录测试一个缓慢的SQL查询

问题描述:

我想测试SQL查询超时处理超过5秒:如何使导轨与活动记录测试一个缓慢的SQL查询

module ActiveRecord 
    module ConnectionAdapters 
    class PostgreSQLAdapter 

     def configure_connection_with_statement_timeout 
     configure_connection_without_statement_timeout 
     ActiveRecord::Base.logger.silence do 
      execute('SET statement_timeout = 5000') 
     end 
     end 
     alias_method_chain :configure_connection, :statement_timeout 

    end 
    end 
end 

但我不知道如何使这样的带有Active Record的慢速SQL查询。的

可能重复:Delay or Wait-For Statement


pg_sleep似乎做到这一点(10秒入睡):

SELECT pg_sleep(10); 

参见:http://blog.endpoint.com/2012/11/how-to-make-postgresql-query-slow.html