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 6fc4393..d7d42ee 100644 --- a/spec/foreman/engine_spec.rb +++ b/spec/foreman/engine_spec.rb @@ -35,7 +35,7 @@ describe "Foreman::Engine" do write_procfile engine = Foreman::Engine.new("Procfile",:concurrency => "alpha=2") mock.instance_of(Foreman::Process).run_process("./alpha", is_a(IO)).twice - mock.instance_of(Foreman::Process).run_process("./bravo", is_a(IO)) + mock.instance_of(Foreman::Process).run_process("./bravo", is_a(IO)).never mock(engine).watch_for_output mock(engine).watch_for_termination engine.start diff --git a/spec/foreman/export/bluepill_spec.rb b/spec/foreman/export/bluepill_spec.rb index b90536c..f0944ae 100644 --- a/spec/foreman/export/bluepill_spec.rb +++ b/spec/foreman/export/bluepill_spec.rb @@ -11,9 +11,18 @@ describe Foreman::Export::Bluepill do before(:each) { load_export_templates_into_fakefs("bluepill") } before(:each) { stub(bluepill).say } - it "exports to the filesystem" do - bluepill.export("/tmp/init", :concurrency => "alpha=2") - File.read("/tmp/init/app.pill").should == example_export_file("bluepill/app.pill") + def normalize_space(s) + s.gsub(/\n[\n\s]*/, "\n") end -end + it "exports to the filesystem" do + bluepill.export("/tmp/init") + normalize_space(File.read("/tmp/init/app.pill")).should == normalize_space(example_export_file("bluepill/app.pill")) + end + + it "exports to the filesystem with concurrency" do + bluepill.export("/tmp/init", :concurrency => "alpha=2") + + normalize_space(File.read("/tmp/init/app.pill")).should == normalize_space(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 6ad23c1..bc582b4 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 6916f9e..4aa797f 100644 --- a/spec/resources/export/bluepill/app.pill +++ b/spec/resources/export/bluepill/app.pill @@ -23,27 +23,6 @@ Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepil 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 - - - - app.process("bravo-1") do |process| process.start_command = "./bravo"