Permalink
Browse files

moved app modification specs into lifecycle_spec

  • Loading branch information...
1 parent 0082fb5 commit b3f240df942dfa6d4ba6df286c94e336b0674f05 David Sabeti and Dmitriy Kalinin committed Apr 1, 2013
Showing with 75 additions and 64 deletions.
  1. +1 −1 assets
  2. +1 −1 config/assets.yml
  3. +8 −0 lib/harness/app.rb
  4. +48 −2 spec/apps/lifecycle_spec.rb
  5. +0 −60 spec/apps/update_spec.rb
  6. +17 −0 spec/support/wait.rb
2 assets
View
@@ -18,8 +18,8 @@ simple_app:
simple_app2:
instances: 1
memory: 512
- command: "bundle exec ruby foo.rb -p $VCAP_APP_PORT"
path: "assets/sinatra/hello_vcap"
+ command: "bundle exec ruby foo.rb -p $VCAP_APP_PORT"
modified_simple_app2:
instances: 2
View
@@ -224,6 +224,9 @@ def unmap(url, options={})
if @session.v2?
host, domain_name = simple.split(".", 2)
+ # New routes might have been added!
+ @app.invalidate!
+
route = @app.routes.find do |r|
r.host == host && r.domain.name == domain_name
end
@@ -439,6 +442,7 @@ def get_response(method, relative_path = "/", data = '', second_domain = nil, ti
path = relative_path.start_with?("/") ? relative_path : "/" + relative_path
url = get_url(second_domain) + path
+ puts "request to '#{url}'"
begin
resource = RestClient::Resource.new(url, :timeout => timeout, :open_timeout => timeout)
case method
@@ -470,6 +474,10 @@ def get_response(method, relative_path = "/", data = '', second_domain = nil, ti
end
end
+ def get(path, domain=nil)
+ get_response(:get, path, "", domain).to_str
+ end
+
def load_manifest(appid = nil)
if !@manifest || appid
unless VCAP_BVT_APP_ASSETS.is_a?(Hash)
@@ -1,5 +1,6 @@
require "harness"
require "spec_helper"
+require "securerandom"
include BVT::Spec
describe "App lifecycle" do
@@ -20,9 +21,13 @@
hash_all = app.stats["0"]
hash_all[:state].should == "RUNNING"
+ # redeploy app
+ app.push(nil, "modified_simple_app2")
+ wait { app.get("/").should =~ /Hello from modified/ }
+
# stop app
app.stop
- app.stats.should == {}
+ wait { app.get("/").should =~ /404 Not Found/ }
# delete app
len = @session.apps.length
@@ -31,13 +36,54 @@
end
end
- describe "slow responding app" do
+ describe "basic app" do
with_app "basic"
it "waits for minimum of 30 seconds of inactivity" do
res = app.get_response(:get, "/sleep?duration=30", "", nil, 100)
res.to_str.should == "slept for 30 secs"
end
+
+ it "is able to scale number of instances" do
+ original_num_of_instances = app.instances.length
+ new_num_of_instances = original_num_of_instances + 2
+ original_memory = 512
+
+ app.scale(new_num_of_instances, original_memory)
+ wait do |i = app.instances|
+ i.map(&:state).uniq.should == ["RUNNING"]
+ i.length.should == new_num_of_instances
+ end
+
+ app.scale(original_num_of_instances, original_memory)
+ wait do |i = app.instances|
+ i.map(&:state).uniq.should == ["RUNNING"]
+ i.length.should == original_num_of_instances
+ end
+ end
+ end
+
+ # Should be combined with 'basic app' tests above
+ # after DEA is fixed to not register instances
+ # that are about to be stopped.
+ describe "basic app (url mapping)" do
+ with_app "basic"
+
+ it "is able to map/unmap a route" do
+ new_subdomain = "#{SecureRandom.hex}"
+
+ app.map(app.get_url(new_subdomain))
+ wait do
+ app.get("/health").should == "ok"
+ app.get("/health", new_subdomain).should == "ok"
+ end
+
+ app.unmap(app.get_url(new_subdomain))
+ wait do
+ app.get("/health").should == "ok"
+ app.get("/health", new_subdomain).should =~ /404 Not Found/
+ end
+ end
end
describe "background worker app (no bound uris)" do
View
@@ -1,60 +0,0 @@
-require "harness"
-require "spec_helper"
-include BVT::Spec
-
-describe "Simple::Update" do
-
- VAR_INC_INSTANCE = 4
- VAR_REDUCE_INSTANCE = 3
- VAR_USE_MEMORY = 64
-
- before(:each) do
- @session = BVT::Harness::CFSession.new
- end
-
- before(:each) do
- @app = create_push_app("simple_app2")
- end
-
- after(:each) do
- @session.cleanup!
- end
-
- it "increase/decrease instance count" do
- added_instance_count = @app.instances.length + VAR_INC_INSTANCE
- @app.scale(added_instance_count, VAR_USE_MEMORY)
- @app.instances.length.should == added_instance_count
-
- reduced_instance_count = @app.instances.length - VAR_REDUCE_INSTANCE
- @app.scale(reduced_instance_count, VAR_USE_MEMORY)
- @app.instances.length.should == reduced_instance_count
- end
-
- it "map and unmap a url for the application to respond to" do
- response = @app.get_response(:get, "/")
- response.to_str.should =~ /Hello from VCAP!/
-
- sleep 0.1
- @app.urls.length.should == 1
- second_domain_name = "new-app-url"
- new_url = @app.get_url(second_domain_name)
- @app.map(new_url)
- response = @app.get_response(:get, "/", nil, second_domain_name)
- response.to_str.should =~ /Hello from VCAP!/
- @app.get_response(:get).to_str.should =~ /Hello from VCAP!/
-
- url = @app.get_url
- @app.unmap(url)
- response = @app.get_response(:get, "/", nil, second_domain_name)
- response.to_str.should =~ /Hello from VCAP!/
- @app.get_response(:get).to_str.should =~ /404 Not Found/
- @app.urls.length.should be(1), "There are more than one url" +
- " mapped to application: #{@app.name}"
- end
-
- it "redeploy application" do
- @app.push(nil, "modified_simple_app2")
- @app.get_response(:get).to_str.should =~ /Hello from modified VCAP/
- end
-
-end
View
@@ -0,0 +1,17 @@
+module WaitHelper
+ def wait(retries_left = 20, &blk)
+ blk.call
+ rescue => e
+ retries_left -= 1
+ if retries_left > 0
+ sleep(1)
+ retry
+ else
+ raise
+ end
+ end
+end
+
+RSpec.configure do |config|
+ config.include(WaitHelper)
+end

0 comments on commit b3f240d

Please sign in to comment.