Module: RSMP::Validator::Lifecycle
- Included in:
- RSMP::Validator
- Defined in:
- lib/rsmp/validator/lifecycle.rb
Overview
Suite lifecycle: startup and shutdown of the Async reactor and auto nodes.
Instance Method Summary collapse
-
#after_suite ⇒ Object
Called at sus shutdown: stops the auto node and reactor.
-
#before_suite ⇒ Object
Called at sus startup: initializes the Async reactor and checks connectivity.
-
#determine_log_stream(sus_config) ⇒ Object
Determine the log stream based on sus config.
-
#setup(sus_config) ⇒ Object
Initialize the validator system at sus startup.
-
#setup_logging ⇒ Object
Set up logging with configuration-specific settings.
-
#setup_reactor ⇒ Object
Initialize the Async reactor.
Instance Method Details
#after_suite ⇒ Object
Called at sus shutdown: stops the auto node and reactor.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rsmp/validator/lifecycle.rb', line 53 def after_suite reactor.run do |_task| auto_node&.stop ensure reactor.interrupt end # Explicitly close the reactor now, while the log stream is still open. # Without this, Ruby's fiber scheduler hook fires after the File.open block # has closed the log file, causing IOError when cancelled tasks try to log. reactor.close rescue StandardError nil end |
#before_suite ⇒ Object
Called at sus startup: initializes the Async reactor and checks connectivity.
42 43 44 45 46 47 48 49 50 |
# File 'lib/rsmp/validator/lifecycle.rb', line 42 def before_suite setup_reactor error = run_startup_checks raise error if error rescue RSMP::ConnectionError => e abort_startup(e, e.) rescue StandardError => e abort_startup(e, e.inspect) end |
#determine_log_stream(sus_config) ⇒ Object
Determine the log stream based on sus config.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rsmp/validator/lifecycle.rb', line 19 def determine_log_stream(sus_config) if sus_config.respond_to?(:log_file_io) && sus_config.log_file_io sus_config.log_file_io elsif sus_config.respond_to?(:log_path) && sus_config.log_path File.open(sus_config.log_path, 'w') elsif sus_config.respond_to?(:log_to_stdout) && sus_config.log_to_stdout $stdout else File.open(File::NULL, 'w') end end |
#setup(sus_config) ⇒ Object
Initialize the validator system at sus startup.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rsmp/validator/lifecycle.rb', line 6 def setup(sus_config) @verbose = sus_config.verbose? @log_stream = determine_log_stream(sus_config) determine_mode sus_config initialize_logging log_settings: {} # minimal init so log() works during config loading load_tester_config load_auto_node_config setup_logging # reinitialize with config-specific settings build_auto_node build_tester end |
#setup_logging ⇒ Object
Set up logging with configuration-specific settings.
32 33 34 35 36 37 38 39 |
# File 'lib/rsmp/validator/lifecycle.rb', line 32 def setup_logging settings = load_log_defaults('validator_log').merge('stream' => @log_stream) settings = settings.deep_merge(config_log_settings) if config_log_settings settings = settings.deep_merge(config['log']) if config.is_a?(Hash) && config['log'] initialize_logging log_settings: settings self.node_log_settings = load_log_defaults('simulator/node_log').merge('stream' => @log_stream) end |
#setup_reactor ⇒ Object
Initialize the Async reactor.
68 69 70 71 |
# File 'lib/rsmp/validator/lifecycle.rb', line 68 def setup_reactor @reactor = Async::Reactor.new reactor.annotate 'reactor' end |