Skip to content

Commit

Permalink
Added tests for Windows and Linux platforms and a bug fix for Windows…
Browse files Browse the repository at this point in the history
… not updating the microtimestamp but every 10 milliseconds, causing domain errors and division by zero. [#46 state:resolved]
  • Loading branch information
mtodd committed Jun 10, 2008
1 parent 05fc53e commit 5d7a5a2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/halcyon.rb
Expand Up @@ -14,7 +14,7 @@
# Halcyon.version #=> "0.5.0"
module Halcyon

VERSION = [0,5,0] unless defined?(Halcyon::VERSION)
VERSION = [0,5,1] unless defined?(Halcyon::VERSION)

autoload :Application, 'halcyon/application'
autoload :Client, 'halcyon/client'
Expand Down Expand Up @@ -54,6 +54,23 @@ def #{attribute.to_s}=(value)
end
alias_method :configurable_attr, :configurable

# Tests for Windows platform (to compensate for numerous Windows-specific
# bugs and oddities.)
#
# Returns Boolean:is_windows
#
def windows?
RUBY_PLATFORM =~ /mswin/
end

# Tests for Linux platform.
#
# Returns Boolean:is_linux
#
def linux?
RUBY_PLATFORM =~ /linux/
end

end

# Creates <tt>Halcyon.db</tt> to alias <tt>Halcyon.config[:db]</tt>.
Expand Down
6 changes: 6 additions & 0 deletions lib/halcyon/application.rb
Expand Up @@ -95,6 +95,12 @@ def call(env)
response.status = result[:status]
response.write result.to_json

# There's a weird bug with Windows that usec is only updated every 10
# millisecs. This slows things down, but hopefully nobody is deploying to
# Windows platforms. This works because it updates the usec time at least
# once to prevent division-by-zero and domain errors.
sleep 0.01 if Halcyon.windows?

timing[:finished] = Time.now
timing[:total] = (((timing[:finished] - timing[:started])*1e4).round.to_f/1e4)
timing[:per_sec] = (((1.0/(timing[:total]))*1e2).round.to_f/1e2)
Expand Down

0 comments on commit 5d7a5a2

Please sign in to comment.