Fix exception in timout rescue when using SystemTimer on 1.8 #12

Merged
merged 1 commit into from Mar 30, 2012
View
@@ -2,3 +2,5 @@ source "http://rubygems.org"
# Specify your gem's dependencies in statsd-instrument.gemspec
gemspec
+
+gem 'SystemTimer', :platform => :mri_18, :require => ''
@@ -16,7 +16,7 @@ class << self
self.enabled = true
self.default_sample_rate = 1
- Timeout = defined?(::SystemTimer) ? ::SystemTimer : ::Timeout
+ TimeoutClass = defined?(::SystemTimer) ? ::SystemTimer : ::Timeout
# StatsD.server = 'localhost:1234'
def self.server=(conn)
@@ -141,7 +141,7 @@ def self.write(k,v,op, sample_rate = default_sample_rate)
end
def self.socket_wrapper(options = {})
- Timeout.timeout(options.fetch(:timeout, 0.1)) { yield }
+ TimeoutClass.timeout(options.fetch(:timeout, 0.1)) { yield }
rescue Timeout::Error, SocketError, IOError, SystemCallError => e
logger.error e
end
@@ -1,3 +1,9 @@
+# Allow testing with the SystemTimer gem on 1.8
+if RUBY_VERSION =~ /^1.8/
+ puts "Loading SystemTimer gem"
+ require 'system_timer'
+end
+
require 'statsd-instrument'
require 'test/unit'
require 'mocha'