@@ -731,10 +731,11 @@ def createRackServletWrapper(runtime, rackup, filename)
731731 end
732732
733733 it "waits acquire timeout till an application is available from the pool (than raises)" do
734+ sleepForMillis = 200
734735 allow ( @factory ) . to receive ( :init )
735736 expect ( @factory ) . to receive ( :newApplication ) . twice do
736737 app = double "app"
737- expect ( app ) . to receive ( :init ) { sleep ( 0.2 ) }
738+ expect ( app ) . to receive ( :init ) { sleep ( sleepForMillis . to_f / 1000 ) }
738739 app
739740 end
740741 allow ( @rack_config ) . to receive ( :getBooleanProperty ) . with ( "jruby.runtime.init.wait" ) . and_return false
@@ -743,18 +744,16 @@ def createRackServletWrapper(runtime, rackup, filename)
743744
744745 @pooling_factory . init ( @rack_context )
745746 @pooling_factory . acquire_timeout = 1 . to_java # second
746- millis = java . lang . System . currentTimeMillis
747+ start = java . lang . System . currentTimeMillis
747748 expect ( @pooling_factory . getApplication ) . not_to be nil
748- millis = java . lang . System . currentTimeMillis - millis
749- expect ( millis ) . to be >= 150 # getApplication waited ~ 0.2 secs
749+ expect ( java . lang . System . currentTimeMillis - start ) . to be_within ( 70 ) . of ( sleepForMillis ) # getApplication waited ~ sleep time
750750
751751 app2 = @pooling_factory . getApplication # now the pool is empty
752-
753- @pooling_factory . acquire_timeout = 0.1 . to_java # second
754- millis = java . lang . System . currentTimeMillis
752+ timeoutMillis = 100
753+ @pooling_factory . acquire_timeout = ( timeoutMillis . to_f / 1000 ) . to_java
754+ start = java . lang . System . currentTimeMillis
755755 expect { @pooling_factory . getApplication } . to raise_error ( org . jruby . rack . AcquireTimeoutException )
756- millis = java . lang . System . currentTimeMillis - millis
757- expect ( millis ) . to be >= 90 # waited about ~ 0.1 secs
756+ expect ( java . lang . System . currentTimeMillis - start ) . to be_within ( 10 ) . of ( timeoutMillis ) # getApplication waited ~ sleep time
758757
759758 @pooling_factory . finishedWithApplication ( app2 ) # gets back to the pool
760759 expect ( @pooling_factory . getApplication ) . to eq app2
0 commit comments