diff --git a/assets b/assets index 927c2c3..d97c718 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 927c2c389e8fbe0780b101365127ea781c155ffe +Subproject commit d97c718fcbac86d7c8f63c8dceedae78e7bc5425 diff --git a/config/assets.yml b/config/assets.yml index e4faa80..c201084 100644 --- a/config/assets.yml +++ b/config/assets.yml @@ -57,21 +57,23 @@ env_test_app: path: "assets/sinatra/env_test_app" command: "bundle exec ruby env_test.rb -p $VCAP_APP_PORT" -broken_app: +# Ruby apps: +ruby18: memory: 512 - path: "assets/sinatra/broken_app" - command: "bundle exec ruby broken.rb -p $VCAP_APP_PORT" + path: "assets/ruby/ruby18" + command: "bundle exec ruby main.rb -p $VCAP_APP_PORT" -git_gems_app_ruby18: +ruby19: memory: 512 - path: "assets/sinatra/git_gems_app" - command: "bundle exec ruby app.rb -p $VCAP_APP_PORT" + path: "assets/ruby/ruby19" + command: "bundle exec ruby main.rb -p $VCAP_APP_PORT" -git_gems_app_ruby19: +rails3: memory: 512 - path: "assets/sinatra/git_gems_app" - command: "bundle exec ruby app.rb -p $VCAP_APP_PORT" + path: "assets/ruby/rails3" + command: "bundle exec rake db:migrate --trace && bundle exec rails server thin -p $PORT" +#- sinatra_gem_groups: memory: 512 path: "assets/sinatra/gem_groups" @@ -87,11 +89,6 @@ broken_gem_app: path: "assets/sinatra/broken_gem_app" command: "bundle exec ruby main.rb -p $VCAP_APP_PORT" -rails3_app: - memory: 512 - path: "assets/rails3/rails3_app" - command: "bundle exec rake db:migrate && bundle exec rails server thin -p $PORT" - jpa_app: memory: 512 path: ".assets-binaries/jpa-guestbook.war" diff --git a/lib/harness/app.rb b/lib/harness/app.rb index 0ce3d79..6122192 100644 --- a/lib/harness/app.rb +++ b/lib/harness/app.rb @@ -94,7 +94,10 @@ def start(need_check = true, async = false, &blk) unless @app.running? @log.info "Start App: #{@app.name}" begin - @app.start!(true, &blk) + @app.start!(true) do |url| + puts "Pushing #{@app.name} - #{url}" + blk.call(url) if blk + end rescue Exception => e @log.error "Start App: #{@app.name} failed.\n#{e.to_s}" raise RuntimeError, "Start App: #{@app.name} failed.\n#{e.to_s}\n#{@session.print_client_logs}" diff --git a/lib/harness/scripts_helper.rb b/lib/harness/scripts_helper.rb index 9b0daeb..711e5e2 100644 --- a/lib/harness/scripts_helper.rb +++ b/lib/harness/scripts_helper.rb @@ -7,45 +7,72 @@ module ScriptsHelper # Service def create_service(service_manifest, name=nil) service_name = name || service_manifest[:vendor] - require_namespace = name.nil? - service = @session.service(service_name, require_namespace) - unless service.available?(service_manifest) - @session.log.debug("Service: (#{service_manifest[:vendor]} #{service_manifest[:version]}) " + - "is not available on target: #{@session.TARGET}") - pending("Service: (#{service_manifest[:vendor]} #{service_manifest[:version]}) " + - "is not available on target: #{@session.TARGET}") + + time_block "create_service '#{service_name}'" do + require_namespace = name.nil? + service = @session.service(service_name, require_namespace) + + unless service.available?(service_manifest) + msg = <<-MSG + Service: + #{service_manifest[:vendor]} + #{service_manifest[:version]} + is not available on target: #{@session.TARGET} + MSG + + @session.log.debug(msg) + pending(msg) + end + + service.create(service_manifest) + service end - service.create(service_manifest) - service end def bind_service(service_manifest, app, name=nil) - service = create_service(service_manifest, name) - app.bind(service) - service + time_block "bind_service '#{app.name}'" do + service = create_service(service_manifest, name) + app.bind(service) + service + end end # Application def create_app(app_name, prefix = '', domain=nil) - app = @session.app(app_name, prefix, domain) - app.load_manifest - if app.manifest['path'].end_with?('.jar') || app.manifest['path'].end_with?('.war') - pending "Package not found, please run update.sh" unless File.exist? app.manifest['path'] + time_block "create_app '#{app_name}'" do + app = @session.app(app_name, prefix, domain) + app.load_manifest + if app.manifest['path'].end_with?('.jar') || app.manifest['path'].end_with?('.war') + pending "Package not found, please run update.sh" unless File.exist? app.manifest['path'] + end + @current_app = app + app end - @current_app = app - app end def create_push_app(app_name, prefix = '', domain=nil, services=[]) - app = create_app(app_name, prefix, domain) - service_instances = services.map do |service| - create_service(service) - end - app.push(service_instances) - unless @session.v2? - app.healthy?.should be_true, "Application #{app.name} is not running" + time_block "create_push_app '#{app_name}'" do + app = create_app(app_name, prefix, domain) + + service_instances = services.map do |service| + create_service(service) + end + + app.push(service_instances) + + unless @session.v2? + app.healthy?.should be_true, "Application #{app.name} is not running" + end + + app end - app + end + + def time_block(name) + t = Time.new + result = yield + puts "Took %.5fs for #{name} to finish" % (Time.now - t) + result end end end diff --git a/spec/apps/info_spec.rb b/spec/apps/info_spec.rb index b42647f..7fadd7d 100644 --- a/spec/apps/info_spec.rb +++ b/spec/apps/info_spec.rb @@ -90,15 +90,6 @@ def get_app_info(apps, appname) crash.files("/app").should_not == nil end - it "get crash information for a broken application" do - app = create_app("broken_app") - app.push(nil, nil, false) - - crash = get_crashes(app.name).first - crash.files("/").should_not == nil - crash.files("/app").should_not == nil - end - def get_crashes(name) app = @client.app_by_name(name) secs = VCAP_BVT_APP_ASSETS["timeout_secs"] diff --git a/spec/apps/lifecycle_spec.rb b/spec/apps/lifecycle_spec.rb index c4c5a5f..3ee4f6a 100644 --- a/spec/apps/lifecycle_spec.rb +++ b/spec/apps/lifecycle_spec.rb @@ -3,10 +3,7 @@ include BVT::Spec describe "Simple::Lifecycle" do - - before(:all) do - @session = BVT::Harness::CFSession.new - end + before(:all) { @session = BVT::Harness::CFSession.new } after(:each) do show_crashlogs @@ -33,5 +30,15 @@ @session.apps.length.should == len - 1 end + #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + # reconsider how to tes + #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + it "is able to run an app that does not bind to ports" do + app = create_push_app("standalone_simple_ruby_app") + app.logs =~ /running version/ + end end - diff --git a/spec/apps/ruby_gems_spec.rb b/spec/apps/ruby_gems_spec.rb deleted file mode 100644 index 0da27cf..0000000 --- a/spec/apps/ruby_gems_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -require "harness" -require "spec_helper" -include BVT::Spec - -describe "Simple::RubyGems" do - before(:all) { @session = BVT::Harness::CFSession.new } - - after do - show_crashlogs - @session.cleanup! - end - - def verify_service(service_manifest, app, key) - data = "#{service_manifest[:vendor]}#{key}" - url = SERVICE_URL_MAPPING[service_manifest[:vendor]] - app.get_response(:post, "/service/#{url}/#{key}", data) - app.get_response(:get, "/service/#{url}/#{key}").to_str.should == data - end - - it "access my application root and see hello from sinatra" do - app = create_push_app("broken_gem_app") - app.stats.should_not == nil - app.get_response(:get).should_not == nil - app.get_response(:get).to_str.should_not == nil - app.get_response(:get).to_str.should == "hello from sinatra" - end - - it "sinatra test deploy app with git gems using ruby19" do - app = create_push_app("git_gems_app_ruby19") - app.stats.should_not == nil - response = app.get_response(:get,"/") - response.code.should == 200 - response.to_str.should == "hello from git" - end - - it "sinatra test deploy app with git gems using ruby18" do - app = create_push_app("git_gems_app_ruby18") - app.stats.should_not == nil - response = app.get_response(:get,"/") - response.code.should == 200 - response.to_str.should == "hello from git" - end - - it "sinatra test deploy app with Gemfile.lock containing Windows versions" do - app = create_push_app("sinatra_windows_gemfile", nil, nil, [MYSQL_MANIFEST, POSTGRESQL_MANIFEST]) - staging_log = app.file("logs/staging_task.log") - staging_log.should_not match "Installing yajl-ruby" - staging_log.should include "Installing mysql2" - staging_log.should include "Installing pg" - - verify_service(MYSQL_MANIFEST, app, "abc") - verify_service(POSTGRESQL_MANIFEST, app, "abc") - end - - it "sinatra test deploy app containing gems specifying a ruby platform" do - app = create_push_app("sinatra_gem_groups") - staging_log = app.file("logs/staging_task.log") - staging_log.should include "Installing uglifier (1.2.6)" - staging_log.should_not include "Installing yajl-ruby (0.8.3)" - - response = app.get_response(:get, "/") - response.code.should == 200 - response.to_str.should == "hello from sinatra" - end -end diff --git a/spec/apps/ruby_rails3_spec.rb b/spec/apps/ruby_rails3_spec.rb deleted file mode 100644 index e777050..0000000 --- a/spec/apps/ruby_rails3_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require "harness" -require "spec_helper" -include BVT::Spec - -describe "Simple::RubyRails3" do - - before(:all) do - @session = BVT::Harness::CFSession.new - end - - after(:each) do - show_crashlogs - @session.cleanup! - end - - it "access my application root and see it's running version" do - @app = create_push_app("app_rails_version", nil, nil, [MYSQL_MANIFEST]) - @app.stats.should_not == nil - - @app.get_response(:get).should_not == nil - @app.get_response(:get).to_str.should_not == nil - @app.get_response(:get).to_str.should == "running version 1.9.2" - end - - it "precompiles assets" do - @app = create_push_app("rails_3_2_app") - @app.stats.should_not == nil - res = @app.get_response(:get, "/assets/manifest.yml") - res.should_not == nil - res.to_str.should match /application.js: application-\w/ - res = @app.get_response(:get, "/assets/application.js") - res.to_str.should match /alert\(\"Hello from CoffeeScript!\"\)/ - end - -end diff --git a/spec/apps/ruby_spec.rb b/spec/apps/ruby_spec.rb index 6e3606d..d323157 100644 --- a/spec/apps/ruby_spec.rb +++ b/spec/apps/ruby_spec.rb @@ -2,24 +2,71 @@ require "spec_helper" include BVT::Spec -describe "Simple::Ruby" do +describe "Ruby" do + before(:all) { @session = BVT::Harness::CFSession.new } - before(:all) do - @session = BVT::Harness::CFSession.new + def self.with_app(app_asset_name) + before(:all) { @app = create_push_app(app_asset_name) } + after(:all) { @session.cleanup! } + define_method(:app) { @app } end - after(:each) do - show_crashlogs - @session.cleanup! + describe "ruby 1.8" do + with_app "ruby18" + + it "starts the app successfully" do + res = app.get_response(:get, "/ruby_version") + res.to_str.should == "1.8.7" + end + + it "supports git gems" do + app.file("logs/staging_task.log").tap do |log| + log.should match %r{Using cf .* git://github.com/cloudfoundry/cf.git} + end + end + + it "installs 1.8 native extensions" do + app.file("logs/staging_task.log").tap do |log| + log.should include "Installing ffi" + end + end end - it "Simple ruby app" do - app = create_push_app("standalone_ruby_app") - app.get_response(:get).to_str.should == "running version 1.9.2" + describe "ruby 1.9" do + with_app "ruby19" + + it "starts the app successfully" do + res = app.get_response(:get, "/ruby_version") + res.to_str.should start_with("1.9") + end + + it "supports git gems" do + app.file("logs/staging_task.log").tap do |log| + log.should match %r{Using cf .* git://github.com/cloudfoundry/cf.git} + end + end + + it "installs 1.9 native extensions" do + app.file("logs/staging_task.log").tap do |log| + log.should include "Installing ffi" + end + end end - it "Simple ruby app and no URL" do - app = create_push_app("standalone_simple_ruby_app") - app.logs =~ /running version 1.9.2/ + describe "rails" do + with_app "rails3" + + it "starts the app successfully" do + res = app.get_response(:get, "/health") + res.to_str.should == "ok" + end end + + #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + # crashlogs + #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!= end