Skip to content

Commit 2aa913f

Browse files
committed
fix value of $PORT
initialize takes a port form cli and decrements it by 1 and sets the instance variable @PORT. This port value is used as the environment variable $PORT inside invoker.ini. When method pick_port gets fired it increments the value of port by 1, subsequently when pick_port again gets fired, for another command, it will again increment port value by 1, that way generating different ports for different commands.
1 parent 44c99a8 commit 2aa913f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/invoker/parsers/config.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ class Config
77
attr_accessor :processes, :power_config
88
attr_reader :filename
99

10+
# initialize takes a port form cli and decrements it by 1 and sets the
11+
# instance variable @port. This port value is used as the environment
12+
# variable $PORT mentioned inside invoker.ini. When method pick_port gets
13+
# fired it increments the value of port by 1, subsequently when pick_port
14+
# again gets fired, for another command, it will again increment port
15+
# value by 1, that way generating different ports for different commands.
1016
def initialize(filename, port)
1117
@filename = filename
12-
@port = port
18+
@port = port - 1
1319
@processes = load_config
1420
if Invoker.can_run_balancer?
1521
@power_config = Invoker::Power::Config.load_config()
@@ -82,7 +88,7 @@ def process_command_from_section(section)
8288

8389
def pick_port(section)
8490
if section['command'] =~ PORT_REGEX
85-
@port
91+
@port += 1
8692
elsif section['port']
8793
section['port']
8894
else

spec/invoker/config_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@
8484

8585
command2 = config.processes[1]
8686

87-
expect(command2.port).to eq(9000)
88-
expect(command2.cmd).to match(/9000/)
87+
expect(command2.port).to eq(9001)
88+
expect(command2.cmd).to match(/9001/)
8989

9090
command2 = config.processes[2]
9191

0 commit comments

Comments
 (0)