@@ -795,27 +795,35 @@ def createRackServletWrapper(runtime, rackup, filename)
795795 expect ( java . lang . System . currentTimeMillis - start ) . to be_within ( 20 ) . of ( timeout_millis )
796796 end
797797
798- it "initializes initial runtimes in paralel (with wait set to false)" do
798+ it "initializes initial runtimes in parallel (with wait set to false)" do
799+ @factory = double ( "factory (non-tracking)" ) . as_null_object
800+ @pooling_factory = org . jruby . rack . PoolingRackApplicationFactory . new @factory
801+ @pooling_factory . context = @rack_context
802+
803+ app_init_secs = 0.05
799804 allow ( @factory ) . to receive ( :init )
800805 allow ( @factory ) . to receive ( :newApplication ) do
801- app = double "app"
802- allow ( app ) . to receive ( :init ) do
803- sleep ( 0.15 )
804- end
806+ app = double ( "app" ) . as_null_object
807+ allow ( app ) . to receive ( :init ) { sleep ( app_init_secs ) }
805808 app
806809 end
810+
811+ init_threads = 4
812+ init_runtimes = 6
807813 allow ( @rack_config ) . to receive ( :getBooleanProperty ) . with ( "jruby.runtime.init.wait" ) . and_return false
808- allow ( @rack_config ) . to receive ( :getInitialRuntimes ) . and_return 6
814+ allow ( @rack_config ) . to receive ( :getRuntimeInitThreads ) . and_return init_threads
815+ allow ( @rack_config ) . to receive ( :getInitialRuntimes ) . and_return init_runtimes
809816 allow ( @rack_config ) . to receive ( :getMaximumRuntimes ) . and_return 8
810817
818+ expected_initial_init_time = 1.1 * ( init_runtimes . to_f / init_threads . to_f ) . ceil * app_init_secs # 10% margin
811819 @pooling_factory . init ( @rack_context )
812- sleep ( 0.10 )
813- expect ( @pooling_factory . getApplicationPool . size ) . to be < 6
814- sleep ( 0.9 )
815- expect ( @pooling_factory . getApplicationPool . size ) . to be >= 6
820+ sleep ( app_init_secs ) # wait for at some (but not possibly all) to finish
821+ expect ( @pooling_factory . getApplicationPool . size ) . to be < init_runtimes
822+ sleep ( expected_initial_init_time - app_init_secs ) # remaining time
823+ expect ( @pooling_factory . getApplicationPool . size ) . to be >= init_runtimes
816824
817825 expect ( @pooling_factory . getManagedApplications ) . to_not be_empty
818- expect ( @pooling_factory . getManagedApplications . size ) . to eql 6
826+ expect ( @pooling_factory . getManagedApplications . size ) . to eql init_runtimes
819827 end
820828
821829 it "throws from init when application initialization in thread failed" do
0 commit comments