From 33aa1efc900a76c3e90682c390f4a9144a99cf84 Mon Sep 17 00:00:00 2001 From: Michael Dwan Date: Mon, 7 Nov 2011 13:10:18 -0700 Subject: [PATCH] default process concurrency is 0 when concurrency options specified, otherwise default concurrency is 1 --- lib/foreman/utils.rb | 5 +- spec/foreman/engine_spec.rb | 1 - spec/foreman/export/bluepill_spec.rb | 7 ++- spec/foreman/export/upstart_spec.rb | 13 ++++- .../export/bluepill/app-concurrency.pill | 47 +++++++++++++++++++ spec/resources/export/bluepill/app.pill | 18 ------- 6 files changed, 68 insertions(+), 23 deletions(-) create mode 100644 spec/resources/export/bluepill/app-concurrency.pill diff --git a/lib/foreman/utils.rb b/lib/foreman/utils.rb index b29ee85..822f4d3 100644 --- a/lib/foreman/utils.rb +++ b/lib/foreman/utils.rb @@ -5,7 +5,10 @@ class Foreman::Utils def self.parse_concurrency(concurrency) begin pairs = concurrency.to_s.gsub(/\s/, "").split(",") - pairs.inject(Hash.new(1)) do |hash, pair| + + default = concurrency.nil? ? 1 : 0 + + pairs.inject(Hash.new(default)) do |hash, pair| process, amount = pair.split("=") hash.update(process => amount.to_i) end diff --git a/spec/foreman/engine_spec.rb b/spec/foreman/engine_spec.rb index 7a20fc2..f857b45 100644 --- a/spec/foreman/engine_spec.rb +++ b/spec/foreman/engine_spec.rb @@ -35,7 +35,6 @@ describe "Foreman::Engine" do engine = Foreman::Engine.new("Procfile",:concurrency => "alpha=2") mock(engine).fork_individual(engine.procfile["alpha"], 1, 5000) mock(engine).fork_individual(engine.procfile["alpha"], 2, 5001) - mock(engine).fork_individual(engine.procfile["bravo"], 1, 5100) mock(engine).watch_for_termination engine.start end diff --git a/spec/foreman/export/bluepill_spec.rb b/spec/foreman/export/bluepill_spec.rb index dd71d87..8dbc4d4 100644 --- a/spec/foreman/export/bluepill_spec.rb +++ b/spec/foreman/export/bluepill_spec.rb @@ -12,9 +12,14 @@ describe Foreman::Export::Bluepill do before(:each) { stub(bluepill).say } it "exports to the filesystem" do - bluepill.export("/tmp/init", :concurrency => "alpha=2") + bluepill.export("/tmp/init") File.read("/tmp/init/app.pill").should == example_export_file("bluepill/app.pill") end + it "exports to the filesystem with concurrency" do + bluepill.export("/tmp/init", :concurrency => "alpha=2") + + File.read("/tmp/init/app.pill").should == example_export_file("bluepill/app-concurrency.pill") + end end \ No newline at end of file diff --git a/spec/foreman/export/upstart_spec.rb b/spec/foreman/export/upstart_spec.rb index 62b3d91..dcfd831 100644 --- a/spec/foreman/export/upstart_spec.rb +++ b/spec/foreman/export/upstart_spec.rb @@ -12,14 +12,23 @@ describe Foreman::Export::Upstart do before(:each) { stub(upstart).say } it "exports to the filesystem" do + upstart.export("/tmp/init") + + File.read("/tmp/init/app.conf").should == example_export_file("upstart/app.conf") + File.read("/tmp/init/app-alpha.conf").should == example_export_file("upstart/app-alpha.conf") + File.read("/tmp/init/app-alpha-1.conf").should == example_export_file("upstart/app-alpha-1.conf") + File.read("/tmp/init/app-bravo.conf").should == example_export_file("upstart/app-bravo.conf") + File.read("/tmp/init/app-bravo-1.conf").should == example_export_file("upstart/app-bravo-1.conf") + end + + it "exports to the filesystem with concurrency" do upstart.export("/tmp/init", :concurrency => "alpha=2") File.read("/tmp/init/app.conf").should == example_export_file("upstart/app.conf") File.read("/tmp/init/app-alpha.conf").should == example_export_file("upstart/app-alpha.conf") File.read("/tmp/init/app-alpha-1.conf").should == example_export_file("upstart/app-alpha-1.conf") File.read("/tmp/init/app-alpha-2.conf").should == example_export_file("upstart/app-alpha-2.conf") - File.read("/tmp/init/app-bravo.conf").should == example_export_file("upstart/app-bravo.conf") - File.read("/tmp/init/app-bravo-1.conf").should == example_export_file("upstart/app-bravo-1.conf") + File.exists?("/tmp/init/app-bravo-1.conf").should == false end context "with alternate templates" do diff --git a/spec/resources/export/bluepill/app-concurrency.pill b/spec/resources/export/bluepill/app-concurrency.pill new file mode 100644 index 0000000..1efd54f --- /dev/null +++ b/spec/resources/export/bluepill/app-concurrency.pill @@ -0,0 +1,47 @@ +Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepill.log") do |app| + + app.uid = "app" + app.gid = "app" + + + + + app.process("alpha-1") do |process| + process.start_command = "./alpha" + + process.working_dir = "/tmp/app" + process.daemonize = true + process.environment = {"PORT" => "5000"} + process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill] + + process.stdout = process.stderr = "/var/log/app/app-alpha-1.log" + + process.monitor_children do |children| + children.stop_command "kill -QUIT {{PID}}" + end + + process.group = "app-alpha" + end + + + app.process("alpha-2") do |process| + process.start_command = "./alpha" + + process.working_dir = "/tmp/app" + process.daemonize = true + process.environment = {"PORT" => "5001"} + process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill] + + process.stdout = process.stderr = "/var/log/app/app-alpha-2.log" + + process.monitor_children do |children| + children.stop_command "kill -QUIT {{PID}}" + end + + process.group = "app-alpha" + end + + + + +end diff --git a/spec/resources/export/bluepill/app.pill b/spec/resources/export/bluepill/app.pill index bef2f13..9d9526d 100644 --- a/spec/resources/export/bluepill/app.pill +++ b/spec/resources/export/bluepill/app.pill @@ -24,24 +24,6 @@ Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepil end - app.process("alpha-2") do |process| - process.start_command = "./alpha" - - process.working_dir = "/tmp/app" - process.daemonize = true - process.environment = {"PORT" => "5001"} - process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill] - - process.stdout = process.stderr = "/var/log/app/app-alpha-2.log" - - process.monitor_children do |children| - children.stop_command "kill -QUIT {{PID}}" - end - - process.group = "app-alpha" - end - - app.process("bravo-1") do |process|