From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 Received: by 10.140.141.15 with HTTP; Sun, 17 Jan 2010 22:59:20 -0800 (PST) In-Reply-To: References: <7ff49577-377c-4374-be17-e114391173a3@k17g2000yqh.googlegroups.com> Date: Mon, 18 Jan 2010 07:59:20 +0100 Delivered-To: chneukirchen@gmail.com Message-ID: Subject: Re: Rack test spec_rack_runtime fails on JRuby due to timing From: Christian Neukirchen To: rack-devel@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Mon, Jan 18, 2010 at 7:38 AM, Ryan Tomayko wrote: > On Sun, Jan 17, 2010 at 10:20 AM, Charles Oliver Nutter > wrote: >> Hey, the following test currently fails on JRuby, but not for a very >> good reason: >> >> =A0specify "should allow multiple timers to be set" do >> =A0 =A0app =3D lambda { |env| sleep 0.1; [200, {'Content-Type' =3D> 'tex= t/ >> plain'}, "Hello, World!"] } >> =A0 =A0runtime1 =3D Rack::Runtime.new(app, "App") >> =A0 =A0runtime2 =3D Rack::Runtime.new(runtime1, "All") >> =A0 =A0response =3D runtime2.call({}) >> >> =A0 =A0response[1]['X-Runtime-App'].should =3D~ /[\d\.]+/ >> =A0 =A0response[1]['X-Runtime-All'].should =3D~ /[\d\.]+/ >> >> =A0 =A0Float(response[1]['X-Runtime-All']).should > Float(response[1]['X= - >> Runtime-App']) >> =A0end >> >> 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: > > =A0 =A0Float(response[1]['X-Runtime-All']).should >=3D > Float(response[1]['X-Runtime-App']) > > ... or removing the assertion entirely. ... or introducing/moving a second sleep. > Thanks, > Ryan > --=20 Christian Neukirchen http://chneukirchen.org