Skip to content

Commit

Permalink
fix broken unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rillbert committed Mar 27, 2021
1 parent 6e82f0c commit 57188ab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/sproc/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def logger
# is nil, that env variable is unset
#
# example callback signature: def my_stdout_cb(line)
def initialize(type = ShellType::NONE, stdout_callback: nil,
def initialize(type: ShellType::NONE, stdout_callback: nil,
stderr_callback: nil, env: {})
@run_opts = {
type: type,
Expand Down
22 changes: 11 additions & 11 deletions test/core_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setup

def test_start_sequential_process
test_str = 'hejsan'
sp = SProc.new(SProc::NONE)
sp = SProc.new(type: SProc::NONE)
info = sp.exec_sync('echo', test_str).task_info
assert_equal("echo #{test_str}", info[:cmd_str])
assert_equal(true, sp.exit_zero?)
Expand All @@ -41,7 +41,7 @@ def test_set_environment_bash

# For command subtitustion, we need a to start the process
# under a shell
sp = SProc.new(SProc::BASH, env: env)
sp = SProc.new(type: SProc::BASH, env: env)
info = sp.exec_sync('echo', test_str).task_info

assert_equal(true, sp.exit_zero?)
Expand All @@ -54,8 +54,8 @@ def test_stdout_callback
nof_pings = 2
matches = 0
SProc.new(
SProc::NONE,
->(line) { (/.*from 127.0.0.1/ =~ line) && (matches += 1) }
type: SProc::NONE,
stdout_callback: ->(line) { (/.*from 127.0.0.1/ =~ line) && (matches += 1) }
).exec_sync('ping', [@count_flag, nof_pings, '127.0.0.1'])

assert_equal(nof_pings, matches)
Expand All @@ -64,21 +64,21 @@ def test_stdout_callback
def test_completion_status
$stdout.sync = true
# expect this to complete ok (with exit code 0)
sp = SProc.new(SProc::NONE).exec_sync('ping', [@count_flag, '1', '127.0.0.1'])
sp = SProc.new(type: SProc::NONE).exec_sync('ping', [@count_flag, '1', '127.0.0.1'])
assert_equal(true, sp.exit_zero?)

# expect this to not have completed when the assert is executed
sp = SProc.new(SProc::NONE).exec_async('ping', [@count_flag, '1', '127.0.0.1'])
sp = SProc.new(type: SProc::NONE).exec_async('ping', [@count_flag, '1', '127.0.0.1'])
assert_equal(false, sp.exit_zero?)
sp.wait_on_completion

# expect this to complete with exit code != 0 since host does not
# exist
sp = SProc.new(SProc::NONE).exec_sync('ping', [@count_flag, '1', 'fake_host'])
sp = SProc.new(type: SProc::NONE).exec_sync('ping', [@count_flag, '1', 'fake_host'])
assert_equal(false, sp.exit_zero?)

# expect this to never start a process since cmd not exists
sp = SProc.new(SProc::NONE).exec_sync('pinggg', [@count_flag, '1', 'fake_host'])
sp = SProc.new(type: SProc::NONE).exec_sync('pinggg', [@count_flag, '1', 'fake_host'])
assert_equal(false, sp.exit_zero?)
assert_equal(ExecutionState::FAILED_TO_START, sp.execution_state)
end
Expand All @@ -87,7 +87,7 @@ def test_start_two_parallel_processes
$stdout.sync = true
msg_array = %w[hej hopp]
p_array = msg_array.collect do |str|
SProc.new(SProc::NONE).exec_async('echo', str)
SProc.new(type: SProc::NONE).exec_async('echo', str)
end
SProc.wait_on_all(p_array)
p_array.each_with_index do |p, i|
Expand All @@ -104,7 +104,7 @@ def test_block_yield_wait_all
# kick-off 4 asynch processes (use ping since it is platform
# independent)
p_array = (1..4).collect do
p = SProc.new(SProc::NONE)
p = SProc.new(type: SProc::NONE)
p.exec_async('ping', [@count_flag,'2', '127.0.0.1'])
end

Expand All @@ -131,7 +131,7 @@ def test_back_to_back
# kick-off 4 asynch processes (use ping since it is platform
# independent)
p_array = (1..4).collect do
p = SProc.new(SProc::NONE)
p = SProc.new(type: SProc::NONE)
p.exec_async('ping',[@count_flag,'2', '127.0.0.1'])
end

Expand Down
16 changes: 8 additions & 8 deletions test/usage_ex_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setup
def test_single_sync
# Intantiate a 'container' for a sub-process that will invoke
# the subprocess under the default shell for the platform
sp = SProc.new(SProc::NONE)
sp = SProc.new(type: SProc::NONE)

# Run 'ping -c 2 127.0.0.1' synchronously as a subprocess, that is,
# we block until it has completed.
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_single_sync
def test_single_async
# Intantiate a 'container' for a sub-process that will invoke
# the subprocess under the default shell for the platform
sp = SProc.new(SProc::NONE)
sp = SProc.new(type: SProc::NONE)

# Run 'ping -c 2 127.0.0.1' asynchronously as a subprocess, that is,
# we don't block while it is running.
Expand Down Expand Up @@ -121,11 +121,11 @@ def test_logging

# Intantiate a 'container' for a sub-process that will invoke
# the subprocess under the default shell for the platform
sp = SProc.new(SProc::NONE)
sp = SProc.new(type: SProc::NONE)

# Run 'ping -c 2 127.0.0.1' asynchronously as a subprocess, that is,
# we don't block while it is running.
sp.exec_sync('ping', [@count_flag, '2', '127.0.0.1'],{chdir: ".."})
sp.exec_sync('ping', [@count_flag, '2', '127.0.0.1'],chdir: "..")
assert(sp.exit_zero?)

# check that something has been logged...
Expand All @@ -137,8 +137,8 @@ def test_logging

def test_wait_on_all
# Kick-off two async subprocesses
sp1 = SProc.new(SProc::NONE).exec_async('ping', [@count_flag, '2', '127.0.0.1'])
sp2 = SProc.new(SProc::NONE).exec_async('ping', [@count_flag, '1', '127.0.0.1'])
sp1 = SProc.new(type: SProc::NONE).exec_async('ping', [@count_flag, '2', '127.0.0.1'])
sp2 = SProc.new(type: SProc::NONE).exec_async('ping', [@count_flag, '1', '127.0.0.1'])
# block until both processes are complete using default poll loop interval
SProc.wait_on_all([sp1, sp2])
# check that they are complete
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_wait_or_back_to_back

# Kick-off one process to start with
p_array = [
SProc.new(SProc::NONE).exec_async('ping', [@count_flag, '2', '127.0.0.1'])
SProc.new(type: SProc::NONE).exec_async('ping', [@count_flag, '2', '127.0.0.1'])
]

nof_not_stared_yet = total_nof_processes - 1
Expand All @@ -181,7 +181,7 @@ def test_wait_or_back_to_back
[
Etc.nprocessors, nof_not_stared_yet
].min.times do
p_new << SProc.new(SProc::NONE).exec_async('ping', [@count_flag, nof_pings, '127.0.0.1'])
p_new << SProc.new(type: SProc::NONE).exec_async('ping', [@count_flag, nof_pings, '127.0.0.1'])
nof_not_stared_yet -= 1
end

Expand Down

0 comments on commit 57188ab

Please sign in to comment.