From ee517e7d931cf75c3d45813426f64a64a2e26f20 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Thu, 8 Nov 2018 12:25:53 -0800 Subject: fix the knife integration spec timeouts rely on killing the thread to terminate the server, and rely on thread#join to correctly signal to the main thread that the server thread is dead, don't leak the server object out of the helper. Signed-off-by: Lamont Granquist --- spec/integration/knife/raw_spec.rb | 18 +++++++++++------- spec/integration/knife/redirection_spec.rb | 10 ++++++---- spec/support/shared/integration/app_server_support.rb | 4 ++-- 3 files changed, 19 insertions(+), 13 deletions(-) (limited to 'spec') diff --git a/spec/integration/knife/raw_spec.rb b/spec/integration/knife/raw_spec.rb index 1c8239746f..04f14be335 100644 --- a/spec/integration/knife/raw_spec.rb +++ b/spec/integration/knife/raw_spec.rb @@ -1,6 +1,6 @@ # # Author:: John Keiser () -# Copyright:: Copyright 2013-2016, Chef Software Inc. +# Copyright:: Copyright 2013-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -190,12 +190,14 @@ EOM app = lambda do |env| [200, { "Content-Type" => "application/json" }, ['{ "x": "y", "a": "b" }'] ] end - @raw_server, @raw_server_thread = start_app_server(app, 9018) + @raw_server_thread = start_app_server(app, 9018) end after :each do - @raw_server.shutdown if @raw_server - @raw_server_thread.kill if @raw_server_thread + if @raw_server_thread + @raw_server_thread.kill + @raw_server_thread.join(30) + end end it "knife raw /blah returns the prettified json", skip: (RUBY_VERSION < "1.9") do @@ -220,12 +222,14 @@ EOM app = lambda do |env| [200, { "Content-Type" => "text" }, ['{ "x": "y", "a": "b" }'] ] end - @raw_server, @raw_server_thread = start_app_server(app, 9018) + @raw_server_thread = start_app_server(app, 9018) end after :each do - @raw_server.shutdown if @raw_server - @raw_server_thread.kill if @raw_server_thread + if @raw_server_thread + @raw_server_thread.kill + @raw_server_thread.join(30) + end 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 29c1ee6ffb..d387b10e3b 100644 --- a/spec/integration/knife/redirection_spec.rb +++ b/spec/integration/knife/redirection_spec.rb @@ -1,6 +1,6 @@ # # Author:: John Keiser () -# Copyright:: Copyright 2013-2016, Chef Software Inc. +# Copyright:: Copyright 2013-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,12 +36,14 @@ describe "redirection", :workstation do app = lambda do |env| [302, { "Content-Type" => "text", "Location" => "#{real_chef_server_url}#{env['PATH_INFO']}" }, ["302 found"] ] end - @redirector_server, @redirector_server_thread = start_app_server(app, 9018) + @redirector_server_thread = start_app_server(app, 9018) end after :each do - @redirector_server.shutdown if @redirector_server - @redirector_thread.kill if @redirector_thread + if @redirector_thread + @redirector_thread.kill + @redirector_thread.join(30) + end end it "knife list /roles returns the role" do diff --git a/spec/support/shared/integration/app_server_support.rb b/spec/support/shared/integration/app_server_support.rb index c0b24d9443..7f05b14689 100644 --- a/spec/support/shared/integration/app_server_support.rb +++ b/spec/support/shared/integration/app_server_support.rb @@ -1,7 +1,7 @@ # # Author:: John Keiser () # Author:: Ho-Sheng Hsiao () -# Copyright:: Copyright 2012-2016 Chef Software, Inc. +# Copyright:: Copyright 2012-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,6 +35,6 @@ module AppServerSupport Timeout.timeout(30) do sleep(0.01) until server && server.status == :Running end - [server, thread] + thread end end -- cgit v1.2.1