diff options
author | John Keiser <john@johnkeiser.com> | 2016-08-18 17:11:12 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2016-08-22 11:57:26 -0700 |
commit | 07da07564be03070ac9a107faf77a33bb7270614 (patch) | |
tree | 0f825a6f6ea3b59c45cb33e2d7177c7a559cab9a /spec/functional/knife | |
parent | 17d1d617c573fe084810a11e542e125f44f7dfc2 (diff) | |
download | chef-07da07564be03070ac9a107faf77a33bb7270614.tar.gz |
Fix TinyServer races.jk/tinyserver-race
1. Wait for the start callback rather than the do block, as it happens
later. This prevents us from getting into many conditions where the
start returns before the server is fully initialized, where if stop()
is called too soon after start returns, it would cause exceptions.
2. Wait for the thread to finish completely
3. Use Thread.current.abort_on_exception` to show the actual listen errors,
so that problems like this can be diagnosed.
4. Use :each to start and stop TinyServer so that race conditions like this
are exposed earlier and more often (this will let us rid ourselves of them
more quickly).
5. Use WEBrick::HTTPServer directly, which gets rid of the need for the
complicated trap workaround (rack is the one that traps).
Diffstat (limited to 'spec/functional/knife')
-rw-r--r-- | spec/functional/knife/cookbook_delete_spec.rb | 10 | ||||
-rw-r--r-- | spec/functional/knife/exec_spec.rb | 10 | ||||
-rw-r--r-- | spec/functional/knife/ssh_spec.rb | 4 |
3 files changed, 12 insertions, 12 deletions
diff --git a/spec/functional/knife/cookbook_delete_spec.rb b/spec/functional/knife/cookbook_delete_spec.rb index a43e3a36c4..99f3309752 100644 --- a/spec/functional/knife/cookbook_delete_spec.rb +++ b/spec/functional/knife/cookbook_delete_spec.rb @@ -20,11 +20,15 @@ require "spec_helper" require "tiny_server" describe Chef::Knife::CookbookDelete do - before(:all) do + before(:each) do @server = TinyServer::Manager.new @server.start end + after(:each) do + @server.stop + end + before(:each) do @knife = Chef::Knife::CookbookDelete.new @api = TinyServer::API.instance @@ -35,10 +39,6 @@ describe Chef::Knife::CookbookDelete do Chef::Config[:chef_server_url] = "http://localhost:9000" end - after(:all) do - @server.stop - end - context "when the cookbook doesn't exist" do let(:log_output) { StringIO.new } diff --git a/spec/functional/knife/exec_spec.rb b/spec/functional/knife/exec_spec.rb index 74d006a8b8..ac8f617a90 100644 --- a/spec/functional/knife/exec_spec.rb +++ b/spec/functional/knife/exec_spec.rb @@ -20,11 +20,15 @@ require "spec_helper" require "tiny_server" describe Chef::Knife::Exec do - before(:all) do + before(:each) do @server = TinyServer::Manager.new #(:debug => true) @server.start end + after(:each) do + @server.stop + end + before(:each) do @knife = Chef::Knife::Exec.new @api = TinyServer::API.instance @@ -37,10 +41,6 @@ describe Chef::Knife::Exec do $output = StringIO.new end - after(:all) do - @server.stop - end - it "executes a script in the context of the chef-shell main context" do @node = Chef::Node.new @node.name("ohai-world") diff --git a/spec/functional/knife/ssh_spec.rb b/spec/functional/knife/ssh_spec.rb index 0f51b765af..065b646ac6 100644 --- a/spec/functional/knife/ssh_spec.rb +++ b/spec/functional/knife/ssh_spec.rb @@ -21,13 +21,13 @@ require "tiny_server" describe Chef::Knife::Ssh do - before(:all) do + before(:each) do Chef::Knife::Ssh.load_deps @server = TinyServer::Manager.new @server.start end - after(:all) do + after(:each) do @server.stop end |