-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FI-2937 inferno execute #517
Merged
Merged
Changes from all commits
Commits
Show all changes
93 commits
Select commit
Hold shift + click to select a range
f9021af
create execute.rb
Shaumik-Ashraf 7d8b8d5
move docker compose option into cli/execute.rb
Shaumik-Ashraf 5a72514
wip
Shaumik-Ashraf 625400d
IT WORKS
Shaumik-Ashraf 72fb726
add force_synchronous kwarg to Jobs
Shaumik-Ashraf 4588c3f
add colorized ascii output
Shaumik-Ashraf de3849d
suppress migration output
Shaumik-Ashraf 6a917f6
create dev_validator_suite
Shaumik-Ashraf d5fbe40
create_params and print_messages functions
Shaumik-Ashraf ea9e592
factorize persist_inputs and verify_runnable functions
Shaumik-Ashraf 71cf9af
add exit codes
Shaumik-Ashraf ff68b3b
add inputs and outputs to verbose
Shaumik-Ashraf df1a988
add long help and fix thor depreciation notice
Shaumik-Ashraf c397a2c
wip rspec
Shaumik-Ashraf aad9453
wip rspec
Shaumik-Ashraf 095117b
debugging
Shaumik-Ashraf 35334b9
debug
Shaumik-Ashraf 7ef1523
rename fetch_test_id to format_id
Shaumik-Ashraf 2df72f3
cleaning
Shaumik-Ashraf d44d408
cop
Shaumik-Ashraf e5670e4
more cop
Shaumik-Ashraf 5c05a7d
Merge remote-tracking branch 'origin/main' into fi-2937-inferno-execute
Shaumik-Ashraf 3ee2b50
verify runnable spec
Shaumik-Ashraf 3bac5e1
fix persist_inputs spec
Shaumik-Ashraf 8038d40
clean
Shaumik-Ashraf d1c5a11
rspec format_result and print_color_results
Shaumik-Ashraf b3b3ac6
cop
Shaumik-Ashraf 2d6ae5a
increase codecov
Shaumik-Ashraf 845f43b
add execute run test
Shaumik-Ashraf 726f1dd
debug
Shaumik-Ashraf 5914d31
add --help to inferno execute; adjust exit codes
Shaumik-Ashraf 25ee150
suppress fhir client logger output
Shaumik-Ashraf a0d2bcb
impl suite options
Shaumik-Ashraf bcc109b
impl group/test execution
Shaumik-Ashraf d0e3b4c
factoring
Shaumik-Ashraf e361b8d
debugging rspec
Shaumik-Ashraf 51f6cf2
rubocopping and cleaning
Shaumik-Ashraf 88c2412
create cli boot via dry-rb system
Shaumik-Ashraf 46be4f7
debug validator sessions loading error
Shaumik-Ashraf f3605be
cop
Shaumik-Ashraf 2ff92e6
the big brain play
Shaumik-Ashraf ef4d8eb
rename cli booter to executor
Shaumik-Ashraf 747d484
lint
Shaumik-Ashraf 150464b
more rspec
Shaumik-Ashraf e3efab0
Merge branch 'main' into fi-2937-inferno-execute
Shaumik-Ashraf 5c85015
In execute_spec.rb rename legit JSON to valid JSON
Shaumik-Ashraf d132650
address util spec, reword test titles, remove useless defined test
Shaumik-Ashraf 23b448e
rename execute_spec#print_color_results test
Shaumik-Ashraf d19b8a8
fix execute.rb multi-line reverse condition
Shaumik-Ashraf f772642
execute_spec make #format_messages tests case sensitive
Shaumik-Ashraf 45353d4
wrap execute help message
Shaumik-Ashraf 729ae9d
factorize format_input and format_output into format_session_data and…
Shaumik-Ashraf d6fef8b
execute_spec JSON parse validation
Shaumik-Ashraf 88709a5
execute_spec remove all stubbed_instance variables
Shaumik-Ashraf a1f9622
execute_spec#set_runnable remove useless test
Shaumik-Ashraf 4162814
fix rubocop but on stderr test
Shaumik-Ashraf e54444a
remove stderr suppression from Execute.suppress_output
Shaumik-Ashraf 209ef99
replace set_runnable with better runnable and runnable_type getters
Shaumik-Ashraf c3ec5f6
rm redundant rspec test_session_inst
Shaumik-Ashraf efb9983
execute.rb fix results title
Shaumik-Ashraf 43b4f53
make --help exit with 0
Shaumik-Ashraf da7acd4
cop
Shaumik-Ashraf 7c36858
replace format_id with format_tag
Shaumik-Ashraf 424d2e2
rspec and cop format_tag
Shaumik-Ashraf 41d7af0
Merge branch 'main' into fi-2937-inferno-execute
Shaumik-Ashraf 7cab803
add yard private tag to new utils
Shaumik-Ashraf c47714a
impl console outputter class
Shaumik-Ashraf 86db812
debugging
Shaumik-Ashraf fa657c7
Merge branch 'fi-2937-inferno-execute' of github.com:inferno-framewor…
Shaumik-Ashraf 94d6a79
debug
Shaumik-Ashraf 641496c
cop
Shaumik-Ashraf 7fbd564
refactor code to take short ids
Shaumik-Ashraf e481fca
cleaning
Shaumik-Ashraf 40073f8
debug
Shaumik-Ashraf 3609646
move repo methods to bottom
Shaumik-Ashraf 8dbe385
resort execute methods in call order
Shaumik-Ashraf 9619e74
wip rspec
Shaumik-Ashraf 6aaf29c
wip rspec
Shaumik-Ashraf df0d205
wip rspec
Shaumik-Ashraf 18e4bbe
wip rspec
Shaumik-Ashraf 098212c
wip rspec
Shaumik-Ashraf 6819b1e
Merge remote-tracking branch 'origin/main' into fi-2937-inferno-execute
Shaumik-Ashraf dcc0463
fix rspec
Shaumik-Ashraf 1969015
remove validator boot from executor boot
Shaumik-Ashraf 9ac3c19
replace -o alias with -u for suite options
Shaumik-Ashraf e973097
Merge branch 'main' into fi-2937-inferno-execute
Shaumik-Ashraf 474dcc5
Merge branch 'main' into fi-2937-inferno-execute
Shaumik-Ashraf 9cb3d39
Merge branch 'main' into fi-2937-inferno-execute
Shaumik-Ashraf e120034
Merge branch 'main' into fi-2937-inferno-execute
Shaumik-Ashraf e690d77
remove bang from find_by_short_id name
Shaumik-Ashraf cd674c0
remove exception raises from abstract methods in abstract outputter
Shaumik-Ashraf 8833d97
yank abstract outputter
Shaumik-Ashraf f796e1d
Merge branch 'main' into fi-2937-inferno-execute
Shaumik-Ashraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
module DevValidatorSuite | ||
class ValidatorSuite < Inferno::TestSuite | ||
title 'Validator Suite' | ||
id :dev_validator | ||
description 'Inferno Core Developer Suite that makes calls to the HL7 Validator.' | ||
|
||
input :url, | ||
title: 'FHIR Server Base Url' | ||
|
||
input :access_token, | ||
title: 'Bearer/Access Token', | ||
optional: true | ||
|
||
fhir_client do | ||
url :url | ||
bearer_token :access_token | ||
end | ||
|
||
fhir_resource_validator do | ||
url 'http://localhost/hl7validatorapi' | ||
end | ||
|
||
group do | ||
title 'Patient Test Group' | ||
id :patient_group | ||
|
||
input :patient_id, | ||
title: 'Patient ID' | ||
|
||
test do | ||
title 'Patient Read Test' | ||
id :patient_read_test | ||
|
||
makes_request :patient_read | ||
|
||
run do | ||
fhir_read(:patient, patient_id, name: :patient_read) | ||
|
||
assert_response_status 200 | ||
end | ||
end | ||
|
||
test do | ||
title 'Patient Validate Test' | ||
id :patient_validate_test | ||
|
||
uses_request :patient_read | ||
|
||
run do | ||
assert_resource_type(:patient) | ||
assert_valid_resource | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
require 'thor' | ||
|
||
require_relative 'cli/main' | ||
|
||
module Inferno | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
require 'pastel' | ||
require 'active_support' | ||
require_relative '../../utils/verify_runnable' | ||
require_relative '../../utils/persist_inputs' | ||
require_relative 'execute/console_outputter' | ||
|
||
module Inferno | ||
module CLI | ||
class Execute | ||
include ::Inferno::Utils::VerifyRunnable | ||
include ::Inferno::Utils::PersistInputs | ||
|
||
attr_accessor :options | ||
|
||
def self.suppress_output | ||
begin | ||
original_stdout = $stdout.clone | ||
$stdout.reopen(File.new(File::NULL, 'w+')) | ||
retval = yield | ||
ensure | ||
$stdout.reopen(original_stdout) | ||
end | ||
retval | ||
end | ||
|
||
def self.boot_full_inferno | ||
ENV['NO_DB'] = 'false' | ||
|
||
# Inferno boot flow triggers migration and logger outputs it | ||
Inferno::CLI::Execute.suppress_output { require_relative '../../../inferno' } | ||
|
||
Inferno::Application.start(:executor) | ||
end | ||
|
||
def run(options) | ||
print_help_and_exit if options[:help] | ||
|
||
self.options = options | ||
|
||
outputter.print_start_message(options) | ||
|
||
results = [] | ||
outputter.print_around_run(options) do | ||
if selected_runnables.empty? | ||
run_one(suite) | ||
results = test_runs_repo.results_for_test_run(test_run(suite).id).reverse | ||
else | ||
selected_runnables.each do |runnable| | ||
run_one(runnable) | ||
results += test_runs_repo.results_for_test_run(test_run(runnable).id).reverse | ||
end | ||
end | ||
end | ||
|
||
outputter.print_results(options, results) | ||
|
||
outputter.print_end_message(options) | ||
|
||
exit(0) if results.all? { |result| result.result == 'pass' } | ||
|
||
# exit(1) is for Thor failures | ||
# exit(2) is for shell builtin failures | ||
exit(3) | ||
rescue Sequel::ValidationFailed => e | ||
print_error_and_exit(e, 4) | ||
rescue Sequel::ForeignKeyConstraintViolation => e | ||
print_error_and_exit(e, 5) | ||
rescue Inferno::Exceptions::RequiredInputsNotFound => e | ||
print_error_and_exit(e, 6) | ||
rescue Inferno::Exceptions::NotUserRunnableException => e | ||
print_error_and_exit(e, 7) | ||
rescue StandardError => e | ||
print_error_and_exit(e, 8) | ||
end | ||
|
||
def print_help_and_exit | ||
puts `NO_DB=true bundle exec inferno help execute` | ||
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, | ||
thor_hash_to_inputs_array(options[:inputs]), | ||
test_session.suite_options | ||
) | ||
|
||
persist_inputs(session_data_repo, create_params(test_session, suite), test_run(runnable)) | ||
|
||
dispatch_job(test_run(runnable)) | ||
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) | ||
@test_runs ||= {} | ||
|
||
@test_runs[runnable_param] ||= test_runs_repo.create( | ||
create_params(test_session, runnable_param).merge({ status: 'queued' }) | ||
) | ||
|
||
@test_runs[runnable_param] | ||
end | ||
|
||
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 | ||
@test_session ||= test_sessions_repo.create({ | ||
test_suite_id: suite.id, | ||
suite_options: thor_hash_to_suite_options_array( | ||
options[:suite_options] | ||
) | ||
}) | ||
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 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 | ||
return [] if options[:groups].blank? | ||
|
||
@groups ||= options[:groups]&.map { |short_id| find_by_short_id(test_groups_repo, short_id) } | ||
end | ||
|
||
def tests | ||
return [] if options[:tests].blank? | ||
|
||
@tests ||= options[:tests]&.map { |short_id| find_by_short_id(tests_repo, short_id) } | ||
end | ||
|
||
def find_by_short_id(repo, short_id) | ||
repo.all.each do |entity| | ||
return entity if short_id == entity.short_id && suite.id == entity.suite.id | ||
end | ||
raise StandardError, "Group or test #{short_id} not found" | ||
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 => e | ||
puts "Caught exception #{e} while printing exception #{err}. Exiting." | ||
ensure | ||
exit(code) | ||
end | ||
|
||
def runnable_type(runnable) | ||
if Inferno::TestSuite.subclasses.include? runnable | ||
:suite | ||
elsif Inferno::TestGroup.subclasses.include? runnable | ||
:group | ||
elsif Inferno::Test.subclasses.include? runnable | ||
:test | ||
else | ||
raise StandardError, "Unidentified runnable #{runnable}" | ||
end | ||
end | ||
|
||
def runnable_id_key(runnable) | ||
case runnable_type(runnable) | ||
when :suite | ||
:test_suite_id | ||
when :group | ||
:test_group_id | ||
else | ||
:test_id | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is doing too much. Display and execution concerns should be separated. This would get even worse once we have multiple output formats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to refactor it in this PR? I could also do it in a JSON-only-output PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored!