rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: Charles Oliver Nutter <headius@headius.com>
To: Rack Development <rack-devel@googlegroups.com>
Subject: Rack test spec_rack_runtime fails on JRuby due to timing
Date: Sun, 17 Jan 2010 10:20:00 -0800 (PST)	[thread overview]
Message-ID: <7ff49577-377c-4374-be17-e114391173a3@k17g2000yqh.googlegroups.com> (raw)

Hey, the following test currently fails on JRuby, but not for a very
good reason:

  specify "should allow multiple timers to be set" do
    app = lambda { |env| sleep 0.1; [200, {'Content-Type' => 'text/
plain'}, "Hello, World!"] }
    runtime1 = Rack::Runtime.new(app, "App")
    runtime2 = Rack::Runtime.new(runtime1, "All")
    response = runtime2.call({})

    response[1]['X-Runtime-App'].should =~ /[\d\.]+/
    response[1]['X-Runtime-All'].should =~ /[\d\.]+/

    Float(response[1]['X-Runtime-All']).should > Float(response[1]['X-
Runtime-App'])
  end

The test here is trying to time that the "All" timer is longer than
the "App" timer. Unfortunately, when running on JRuby, the All time is
often below 1ms, which is shorter than the granularity for our Time
class (JVM only provides current time to 1ms granularity). As a
result, the test usually fails.

This came up because a friend of JRuby is working to prepare a Gentoo
ebuild, and wants to get all related packages running green.

I'm not sure the best way to fix this; the difference in execution
time between the "App" and the "All" wrapper are very small, and a
timing test like this is probably going to be unpredictable. I have
made a JRuby-specific patch here to use the JVM's nanosecond timer
(which can be used for deltas but not absolute times), but it's
obviously JRuby-specific:

http://gist.github.com/279475

Running the tests with this modification shows the "All" time to range
around 0.00015s and the "App" time around 0.00003s.

Thoughts?

- Charlie

             reply	other threads:[~2010-01-17 19:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-17 18:20 Charles Oliver Nutter [this message]
2010-01-18  6:38 ` Rack test spec_rack_runtime fails on JRuby due to timing Ryan Tomayko
2010-01-18  6:59   ` Christian Neukirchen
2010-01-18 17:17     ` Charles Oliver Nutter
2010-02-08 19:38       ` Ryan Tomayko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7ff49577-377c-4374-be17-e114391173a3@k17g2000yqh.googlegroups.com \
    --to=rack-devel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).