From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.140.141.15 with SMTP id o15cs383285rvd; Sun, 17 Jan 2010 22:38:53 -0800 (PST) Received: from mr.google.com ([10.224.106.163]) by 10.224.106.163 with SMTP id x35mr727567qao.18.1263796732821 (num_hops = 1); Sun, 17 Jan 2010 22:38:52 -0800 (PST) Received: by 10.224.106.163 with SMTP id x35mr42850qao.18.1263796730973; Sun, 17 Jan 2010 22:38:50 -0800 (PST) X-BeenThere: rack-devel@googlegroups.com Received: by 10.229.68.219 with SMTP id w27ls336625qci.2.p; Sun, 17 Jan 2010 22:38:48 -0800 (PST) Received: by 10.229.30.139 with SMTP id u11mr962113qcc.6.1263796728006; Sun, 17 Jan 2010 22:38:48 -0800 (PST) Received: by 10.229.30.139 with SMTP id u11mr962112qcc.6.1263796727968; Sun, 17 Jan 2010 22:38:47 -0800 (PST) Return-Path: Received: from qw-out-1920.google.com (qw-out-1920.google.com [74.125.92.146]) by gmr-mx.google.com with ESMTP id 25si1482665qyk.15.2010.01.17.22.38.46; Sun, 17 Jan 2010 22:38:46 -0800 (PST) Received-SPF: pass (google.com: domain of rtomayko@gmail.com designates 74.125.92.146 as permitted sender) client-ip=74.125.92.146; Received: by qw-out-1920.google.com with SMTP id 5so616531qwc.38 for ; Sun, 17 Jan 2010 22:38:46 -0800 (PST) MIME-Version: 1.0 Sender: rack-devel@googlegroups.com Received: by 10.224.97.99 with SMTP id k35mr4141401qan.328.1263796726844; Sun, 17 Jan 2010 22:38:46 -0800 (PST) In-Reply-To: <7ff49577-377c-4374-be17-e114391173a3@k17g2000yqh.googlegroups.com> References: <7ff49577-377c-4374-be17-e114391173a3@k17g2000yqh.googlegroups.com> Date: Sun, 17 Jan 2010 22:38:46 -0800 Message-ID: Subject: Re: Rack test spec_rack_runtime fails on JRuby due to timing From: Ryan Tomayko To: rack-devel@googlegroups.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of rtomayko@gmail.com designates 74.125.92.146 as permitted sender) smtp.mail=rtomayko@gmail.com; dkim=pass (test mode) header.i=@gmail.com X-Original-Sender: r@tomayko.com Reply-To: rack-devel@googlegroups.com Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: X-Thread-Url: http://groups.google.com/group/rack-devel/t/867a2dbeaf914afb X-Message-Url: http://groups.google.com/group/rack-devel/msg/8346970c436d8d0f List-Unsubscribe: , List-Subscribe: , Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: > > =C2=A0specify "should allow multiple timers to be set" do > =C2=A0 =C2=A0app =3D lambda { |env| sleep 0.1; [200, {'Content-Type' =3D>= 'text/ > plain'}, "Hello, World!"] } > =C2=A0 =C2=A0runtime1 =3D Rack::Runtime.new(app, "App") > =C2=A0 =C2=A0runtime2 =3D Rack::Runtime.new(runtime1, "All") > =C2=A0 =C2=A0response =3D runtime2.call({}) > > =C2=A0 =C2=A0response[1]['X-Runtime-App'].should =3D~ /[\d\.]+/ > =C2=A0 =C2=A0response[1]['X-Runtime-All'].should =3D~ /[\d\.]+/ > > =C2=A0 =C2=A0Float(response[1]['X-Runtime-All']).should > Float(response[= 1]['X- > Runtime-App']) > =C2=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: Float(response[1]['X-Runtime-All']).should >=3D Float(response[1]['X-Runtime-App']) ... or removing the assertion entirely. Thanks, Ryan