Skip to content

Commit

Permalink
resort execute methods in call order
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaumik-Ashraf committed Sep 10, 2024
1 parent 3609646 commit 8dbe385
Showing 1 changed file with 63 additions and 65 deletions.
128 changes: 63 additions & 65 deletions lib/inferno/apps/cli/execute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ def print_help_and_exit
exit(0)
end

def outputter
# TODO: swap outputter based on options
@outputter ||= Inferno::CLI::Execute::ConsoleOutputter.new
end

def selected_runnables
groups + tests
end

def run_one(runnable)
verify_runnable(
suite,
Expand All @@ -90,15 +99,16 @@ def run_one(runnable)
dispatch_job(test_run(runnable))
end

def dispatch_job(test_run)
# TODO: move suppression to outputter? better suppresion?
if options[:verbose]
Jobs.perform(Jobs::ExecuteTestRun, test_run.id, force_synchronous: true)
else
Inferno::CLI::Execute.suppress_output do
Jobs.perform(Jobs::ExecuteTestRun, test_run.id, force_synchronous: true)
end
end
def suite
@suite ||= Inferno::Repositories::TestSuites.new.find(options[:suite])

raise StandardError, "Test suite #{options[:suite]} not found" if @suite.nil?

@suite
end

def test_runs_repo
@test_runs_repo ||= Inferno::Repositories::TestRuns.new
end

def test_run(runnable_param)
Expand All @@ -111,12 +121,20 @@ def test_run(runnable_param)
@test_runs[runnable_param]
end

def create_params(test_session, runnable)
{
test_session_id: test_session.id,
runnable_id_key(runnable) => runnable.id,
inputs: thor_hash_to_inputs_array(options[:inputs])
}
def test_groups_repo
@test_groups_repo ||= Inferno::Repositories::TestGroups.new
end

def tests_repo
@tests_repo ||= Inferno::Repositories::Tests.new
end

def test_sessions_repo
@test_sessions_repo ||= Inferno::Repositories::TestSessions.new
end

def session_data_repo
@session_data_repo ||= Inferno::Repositories::SessionData.new
end

def test_session
Expand All @@ -128,13 +146,23 @@ def test_session
})
end

def create_params(test_session, runnable)
{
test_session_id: test_session.id,
runnable_id_key(runnable) => runnable.id,
inputs: thor_hash_to_inputs_array(options[:inputs])
}
end

def suite
@suite ||= Inferno::Repositories::TestSuites.new.find(options[:suite])

raise StandardError, "Test suite #{options[:suite]} not found" if @suite.nil?

@suite
def dispatch_job(test_run)
# TODO: move suppression to outputter? better suppression?
if options[:verbose]
Jobs.perform(Jobs::ExecuteTestRun, test_run.id, force_synchronous: true)
else
Inferno::CLI::Execute.suppress_output do
Jobs.perform(Jobs::ExecuteTestRun, test_run.id, force_synchronous: true)
end
end
end

def groups
Expand All @@ -154,8 +182,20 @@ def find_by_short_id!(repo, short_id)
raise StandardError, "Group or test #{short_id} not found"
end

def selected_runnables
groups + tests
def thor_hash_to_suite_options_array(hash = {})
hash.to_a.map { |pair| Inferno::DSL::SuiteOption.new({ id: pair[0], value: pair[1] }) }
end

def thor_hash_to_inputs_array(hash = {})
hash.to_a.map { |pair| { name: pair[0], value: pair[1] } }
end

def print_error_and_exit(err, code)
outputter.print_error(options || {}, err)
rescue StandardError => outputter_err
puts "Caught exception #{outputter_err} while printing exception #{err}. Exiting."
ensure
exit(code)
end

def runnable_type(runnable)
Expand All @@ -180,48 +220,6 @@ def runnable_id_key(runnable)
:test_id
end
end

def thor_hash_to_suite_options_array(hash = {})
hash.to_a.map { |pair| Inferno::DSL::SuiteOption.new({ id: pair[0], value: pair[1] }) }
end

def thor_hash_to_inputs_array(hash = {})
hash.to_a.map { |pair| { name: pair[0], value: pair[1] } }
end

def print_error_and_exit(err, code)
outputter.print_error(options || {}, err)
rescue StandardError => outputter_err
puts "Caught exception #{outputter_err} while printing exception #{err}. Exiting."
ensure
exit(code)
end

def outputter
# TODO: swap outputter based on options
@outputter ||= Inferno::CLI::Execute::ConsoleOutputter.new
end

def test_sessions_repo
@test_sessions_repo ||= Inferno::Repositories::TestSessions.new
end

def session_data_repo
@session_data_repo ||= Inferno::Repositories::SessionData.new
end

def test_runs_repo
@test_runs_repo ||= Inferno::Repositories::TestRuns.new
end

def test_groups_repo
@test_groups_repo ||= Inferno::Repositories::TestGroups.new
end

def tests_repo
@tests_repo ||= Inferno::Repositories::Tests.new
end

end
end
end

0 comments on commit 8dbe385

Please sign in to comment.