rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: Christian Neukirchen <chneukirchen@gmail.com>
To: rack-devel@googlegroups.com
Subject: Re: Rack test spec_rack_runtime fails on JRuby due to timing
Date: Mon, 18 Jan 2010 07:59:20 +0100	[thread overview]
Message-ID: <e064621a1001172259r67f70ec9h70b21e3ae1f6b17f@mail.gmail.com> (raw)
In-Reply-To: <f732822d1001172238u5bdc25a1v1e7c0677856e1532@mail.gmail.com>

On Mon, Jan 18, 2010 at 7:38 AM, Ryan Tomayko <r@tomayko.com> wrote:
> On Sun, Jan 17, 2010 at 10:20 AM, Charles Oliver Nutter
> <headius@headius.com> wrote:
>> 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?
>
> Perhaps changing the assertion to be:
>
>    Float(response[1]['X-Runtime-All']).should >=
> Float(response[1]['X-Runtime-App'])
>
> ... or removing the assertion entirely.

... or introducing/moving a second sleep.

> Thanks,
> Ryan
>
-- 
Christian Neukirchen  <chneukirchen@gmail.com>  http://chneukirchen.org

  reply	other threads:[~2010-01-18  6:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-17 18:20 Rack test spec_rack_runtime fails on JRuby due to timing Charles Oliver Nutter
2010-01-18  6:38 ` Ryan Tomayko
2010-01-18  6:59   ` Christian Neukirchen [this message]
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=e064621a1001172259r67f70ec9h70b21e3ae1f6b17f@mail.gmail.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).