summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-08-28 16:40:52 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-08-28 16:40:52 -0700
commitc106a633ef28f5d53cac6bfa64adaddd3aa2f9ca (patch)
tree2169aa191c9de1fc35a106a7af4249c0e8f02852
parentafb519b0a35ca36d6762b300d55911a4dc39b1e1 (diff)
downloadchef-lcg/remove-support-spec.tar.gz
remove app_server_support spec filelcg/remove-support-spec
Convert to using TinyServer and remove the duplicated functionality with the "app_server_support" helper. The fact that this change hits the knife raw / knife redirection specs that have so many timeout issues is very likely not a coincidence. I would bet a small, but not entirely insignificant amount of money that this makes those timeout issues go away. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--spec/integration/knife/raw_spec.rb58
-rw-r--r--spec/integration/knife/redirection_spec.rb35
-rw-r--r--spec/integration/knife/serve_spec.rb3
-rw-r--r--spec/support/shared/integration/app_server_support.rb39
-rw-r--r--spec/support/shared/integration/integration_helper.rb3
5 files changed, 63 insertions, 75 deletions
diff --git a/spec/integration/knife/raw_spec.rb b/spec/integration/knife/raw_spec.rb
index 9fd7664ddd..99fb7b5787 100644
--- a/spec/integration/knife/raw_spec.rb
+++ b/spec/integration/knife/raw_spec.rb
@@ -19,11 +19,11 @@ require "support/shared/integration/integration_helper"
require "support/shared/context/config"
require "chef/knife/raw"
require "chef/knife/show"
+require "tiny_server"
describe "knife raw", :workstation do
include IntegrationSupport
include KnifeSupport
- include AppServerSupport
include_context "default config options"
@@ -185,19 +185,29 @@ describe "knife raw", :workstation do
end
context "When a server returns raw json" do
- before :each do
- Chef::Config.chef_server_url = "http://localhost:9018"
- app = lambda do |env|
- [200, { "Content-Type" => "application/json" }, ['{ "x": "y", "a": "b" }'] ]
+ def start_tiny_server(server_opts = {})
+ @server = TinyServer::Manager.new(server_opts)
+ @server.start
+ @api = TinyServer::API.instance
+ @api.clear
+
+ @api.get("/blah", 200, nil, { "Content-Type" => "application/json" }) do
+ '{ "x": "y", "a": "b" }'
end
- @raw_server_thread = start_app_server(app, 9018)
+ end
+
+ def stop_tiny_server
+ @server.stop
+ @server = @api = nil
+ end
+
+ before :each do
+ Chef::Config.chef_server_url = "http://localhost:9000"
+ start_tiny_server
end
after :each do
- if @raw_server_thread
- @raw_server_thread.kill
- @raw_server_thread.join(30)
- end
+ stop_tiny_server
end
it "knife raw /blah returns the prettified json" do
@@ -217,19 +227,29 @@ describe "knife raw", :workstation do
end
context "When a server returns text" do
- before :each do
- Chef::Config.chef_server_url = "http://localhost:9018"
- app = lambda do |env|
- [200, { "Content-Type" => "text" }, ['{ "x": "y", "a": "b" }'] ]
+ def start_tiny_server(server_opts = {})
+ @server = TinyServer::Manager.new(server_opts)
+ @server.start
+ @api = TinyServer::API.instance
+ @api.clear
+
+ @api.get("/blah", 200, nil, { "Content-Type" => "text" }) do
+ '{ "x": "y", "a": "b" }'
end
- @raw_server_thread = start_app_server(app, 9018)
+ end
+
+ def stop_tiny_server
+ @server.stop
+ @server = @api = nil
+ end
+
+ before :each do
+ Chef::Config.chef_server_url = "http://localhost:9000"
+ start_tiny_server
end
after :each do
- if @raw_server_thread
- @raw_server_thread.kill
- @raw_server_thread.join(30)
- end
+ stop_tiny_server
end
it "knife raw /blah returns the raw text" do
diff --git a/spec/integration/knife/redirection_spec.rb b/spec/integration/knife/redirection_spec.rb
index 5e5ef27b9a..fe39315fe4 100644
--- a/spec/integration/knife/redirection_spec.rb
+++ b/spec/integration/knife/redirection_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: John Keiser (<jkeiser@chef.io>)
-# Copyright:: Copyright 2013-2018, Chef Software Inc.
+# Copyright:: Copyright 2013-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,6 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+require "tiny_server"
require "support/shared/integration/integration_helper"
require "support/shared/context/config"
require "chef/knife/list"
@@ -22,7 +23,21 @@ require "chef/knife/list"
describe "redirection", :workstation do
include IntegrationSupport
include KnifeSupport
- include AppServerSupport
+
+ def start_tiny_server(real_chef_server_url, server_opts = {})
+ @server = TinyServer::Manager.new(server_opts)
+ @server.start
+ @api = TinyServer::API.instance
+ @api.clear
+
+ @api.get("/roles", 302, nil, { "Content-Type" => "text", "Location" => "#{real_chef_server_url}/roles" }) do
+ end
+ end
+
+ def stop_tiny_server
+ @server.stop
+ @server = @api = nil
+ end
include_context "default config options"
@@ -30,20 +45,14 @@ describe "redirection", :workstation do
before { role "x", {} }
context "and another server redirects to it with 302" do
- before :each do
+ before(:each) do
real_chef_server_url = Chef::Config.chef_server_url
- Chef::Config.chef_server_url = "http://localhost:9018"
- app = lambda do |env|
- [302, { "Content-Type" => "text", "Location" => "#{real_chef_server_url}#{env["PATH_INFO"]}" }, ["302 found"] ]
- end
- @redirector_server_thread = start_app_server(app, 9018)
+ Chef::Config.chef_server_url = "http://localhost:9000"
+ start_tiny_server(real_chef_server_url)
end
- after :each do
- if @redirector_thread
- @redirector_thread.kill
- @redirector_thread.join(30)
- end
+ after(:each) do
+ stop_tiny_server
end
it "knife list /roles returns the role" do
diff --git a/spec/integration/knife/serve_spec.rb b/spec/integration/knife/serve_spec.rb
index b0cdd8c070..ab293174d4 100644
--- a/spec/integration/knife/serve_spec.rb
+++ b/spec/integration/knife/serve_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: John Keiser (<jkeiser@chef.io>)
-# Copyright:: Copyright 2013-2016, Chef Software Inc.
+# Copyright:: Copyright 2013-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@ require "chef/server_api"
describe "knife serve", :workstation do
include IntegrationSupport
include KnifeSupport
- include AppServerSupport
def with_knife_serve
exception = nil
diff --git a/spec/support/shared/integration/app_server_support.rb b/spec/support/shared/integration/app_server_support.rb
deleted file mode 100644
index 317a5a2679..0000000000
--- a/spec/support/shared/integration/app_server_support.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# Author:: John Keiser (<jkeiser@chef.io>)
-# Author:: Ho-Sheng Hsiao (<hosh@chef.io>)
-# Copyright:: Copyright 2012-2018, Chef Software Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require "rack"
-require "stringio"
-
-module AppServerSupport
- def start_app_server(app, port)
- server = nil
- thread = Thread.new do
- Rack::Handler::WEBrick.run(app,
- Port: 9018,
- AccessLog: [],
- Logger: WEBrick::Log.new(StringIO.new, 7)) do |found_server|
- server = found_server
- end
- end
- Timeout.timeout(30) do
- sleep(0.01) until server && server.status == :Running
- end
- thread
- end
-end
diff --git a/spec/support/shared/integration/integration_helper.rb b/spec/support/shared/integration/integration_helper.rb
index 6c0eca98be..f0dfd1dc43 100644
--- a/spec/support/shared/integration/integration_helper.rb
+++ b/spec/support/shared/integration/integration_helper.rb
@@ -1,7 +1,7 @@
#
# Author:: John Keiser (<jkeiser@chef.io>)
# Author:: Ho-Sheng Hsiao (<hosh@chef.io>)
-# Copyright:: Copyright 2012-2016, Chef Software Inc.
+# Copyright:: Copyright 2012-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +23,6 @@ require "chef/config"
require "chef/json_compat"
require "chef/server_api"
require "support/shared/integration/knife_support"
-require "support/shared/integration/app_server_support"
require "cheffish/rspec/chef_run_support"
require "spec_helper"