Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
unify ruby app specs into a single spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Bleicke and Dmitriy Kalinin committed Mar 23, 2013
1 parent 2e77ab6 commit 55dd0db
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 168 deletions.
2 changes: 1 addition & 1 deletion assets
25 changes: 11 additions & 14 deletions config/assets.yml
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion lib/harness/app.rb
Expand Up @@ -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}"
Expand Down
79 changes: 53 additions & 26 deletions lib/harness/scripts_helper.rb
Expand Up @@ -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
9 changes: 0 additions & 9 deletions spec/apps/info_spec.rb
Expand Up @@ -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"]
Expand Down
17 changes: 12 additions & 5 deletions spec/apps/lifecycle_spec.rb
Expand Up @@ -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
Expand All @@ -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

65 changes: 0 additions & 65 deletions spec/apps/ruby_gems_spec.rb

This file was deleted.

35 changes: 0 additions & 35 deletions spec/apps/ruby_rails3_spec.rb

This file was deleted.

71 changes: 59 additions & 12 deletions spec/apps/ruby_spec.rb
Expand Up @@ -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

0 comments on commit 55dd0db

Please sign in to comment.