|
| 1 | +require 'net/http' |
| 2 | + |
| 3 | +describe 'kontena service shutdown' do |
| 4 | + include ServiceHelper |
| 5 | + |
| 6 | + context 'for a http test service' do |
| 7 | + before(:all) do |
| 8 | + with_fixture_dir('stack/shutdown-test') do |
| 9 | + run! 'kontena stack build --no-push' |
| 10 | + end |
| 11 | + end |
| 12 | + |
| 13 | + context "using ungraceful shutdown to fail requests" do |
| 14 | + before(:all) do |
| 15 | + with_fixture_dir('stack/shutdown-test') do |
| 16 | + run! "kontena stack install -n shutdown-test-fail -v trap=false" |
| 17 | + end |
| 18 | + end |
| 19 | + after(:all) do |
| 20 | + run! 'kontena stack rm --force shutdown-test-fail' |
| 21 | + end |
| 22 | + |
| 23 | + describe "after re-deploying the server" do |
| 24 | + before do |
| 25 | + run! 'kontena service deploy --force shutdown-test-fail/server' |
| 26 | + end |
| 27 | + |
| 28 | + it "will result in client errors" do |
| 29 | + events = service_events('shutdown-test-fail/client') |
| 30 | + |
| 31 | + expect(events.select{|e| e[:type] == 'instance_crash'}).to_not eq([]), service_logs('shutdown-test-fail/client').join |
| 32 | + end |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + context "using graceful shutdown to close the listening socket" do |
| 37 | + before(:all) do |
| 38 | + with_fixture_dir('stack/shutdown-test') do |
| 39 | + run! "kontena stack install -n shutdown-test-graceful -v graceful_shutdown=true" |
| 40 | + end |
| 41 | + end |
| 42 | + after(:all) do |
| 43 | + run! 'kontena stack rm --force shutdown-test-graceful' |
| 44 | + end |
| 45 | + |
| 46 | + describe "after re-deploying the server" do |
| 47 | + before do |
| 48 | + run! 'kontena service deploy --force shutdown-test-graceful/server' |
| 49 | + end |
| 50 | + |
| 51 | + it "does not result in any client errors" do |
| 52 | + events = service_events('shutdown-test-graceful/client') |
| 53 | + |
| 54 | + expect(events.select{|e| e[:type] == 'instance_crash'}).to eq([]), service_logs('shutdown-test-graceful/client').join |
| 55 | + end |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + context "using graceful shutdown without a healthcheck" do |
| 60 | + before(:all) do |
| 61 | + with_fixture_dir('stack/shutdown-test') do |
| 62 | + run! "kontena stack install -n shutdown-test-nohealthcheck -v graceful_shutdown=true -v healthcheck=false" |
| 63 | + end |
| 64 | + end |
| 65 | + after(:all) do |
| 66 | + run! 'kontena stack rm --force shutdown-test-nohealthcheck' |
| 67 | + end |
| 68 | + |
| 69 | + describe "after re-deploying the server" do |
| 70 | + before do |
| 71 | + run! 'kontena service deploy --force shutdown-test-nohealthcheck/server' |
| 72 | + end |
| 73 | + |
| 74 | + it "does not result in any client errors" do |
| 75 | + events = service_events('shutdown-test-nohealthcheck/client') |
| 76 | + |
| 77 | + expect(events.select{|e| e[:type] == 'instance_crash'}).to eq([]), service_logs('shutdown-test-nohealthcheck/client').join |
| 78 | + end |
| 79 | + end |
| 80 | + end |
| 81 | + |
| 82 | + context "using delayed shutdown without closing the listening socket" do |
| 83 | + before(:all) do |
| 84 | + with_fixture_dir('stack/shutdown-test') do |
| 85 | + run! "kontena stack install -n shutdown-test-delay -v graceful_shutdown=false" |
| 86 | + end |
| 87 | + end |
| 88 | + after(:all) do |
| 89 | + run! 'kontena stack rm --force shutdown-test-delay' |
| 90 | + end |
| 91 | + |
| 92 | + describe "after re-deploying the server" do |
| 93 | + before do |
| 94 | + run! 'kontena service deploy --force shutdown-test-delay/server' |
| 95 | + end |
| 96 | + |
| 97 | + it "does not result in any client errors" do |
| 98 | + events = service_events('shutdown-test-delay/client') |
| 99 | + |
| 100 | + expect(events.select{|e| e[:type] == 'instance_crash'}).to eq([]), service_logs('shutdown-test-delay/client').join |
| 101 | + end |
| 102 | + end |
| 103 | + end |
| 104 | + end |
| 105 | +end |
0 commit comments