Class: TestRunner::Cli::Command
- Inherits:
-
OsCtl::Lib::Cli::Command
- Object
- OsCtl::Lib::Cli::Command
- TestRunner::Cli::Command
- Defined in:
- lib/test-runner/cli/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #debug ⇒ Object
- #jobs_auto? ⇒ Boolean protected
- #list ⇒ Object
- #load_extensions ⇒ Object protected
- #original_repo_root ⇒ Object protected
- #repo_root ⇒ Object protected
- #select_test_scripts(pattern) ⇒ Array<TestScript> protected
- #state_dir ⇒ Object protected
- #test ⇒ Object
- #test_config_path ⇒ Object protected
- #test_jobs(test_scripts) ⇒ Object protected
- #with_repository_environment(source_path) ⇒ Object protected
- #with_repository_source ⇒ Object protected
Class Method Details
.run(method) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/test-runner/cli/command.rb', line 5 def self.run(method) proc do |global_opts, opts, args| cmd = new(global_opts, opts, args) cmd.send(:with_repository_source) do cmd.send(:load_extensions) cmd.method(method).call end end end |
Instance Method Details
#debug ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/test-runner/cli/command.rb', line 80 def debug require_args!('test') tsl = TestRunner::TestScriptList.new(system: opts['system'], test_config_path:, repo_root:) test_script = tsl.by_path(args[0]) directory = TestState.directory(state_dir, test_script.test) TestState.with_lock(directory) do ev = TestRunner::TestEvaluator.new( test_script.test, [test_script], system: opts['system'], test_config_path:, repo_root:, state_dir: directory, sock_dir: File.join(state_dir, 'socks'), default_timeout: opts['timeout'], destructive: false, recreate_disks: opts['fresh'] ) ev.interactive end end |
#jobs_auto? ⇒ Boolean (protected)
115 116 117 |
# File 'lib/test-runner/cli/command.rb', line 115 def jobs_auto? opts['jobs'].to_s == 'auto' end |
#list ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/test-runner/cli/command.rb', line 15 def list test_scripts = select_test_scripts(args[0]) test_scripts.each do |ts| puts ts.path end end |
#load_extensions ⇒ Object (protected)
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/test-runner/cli/command.rb', line 183 def load_extensions return if @extensions_loaded @extensions_loaded = true ext_dir = File.join(original_repo_root, 'tests', 'runner', 'extensions') return unless Dir.exist?(ext_dir) Dir[File.join(ext_dir, '*.rb')].each do |file| load(file) end end |
#original_repo_root ⇒ Object (protected)
147 148 149 |
# File 'lib/test-runner/cli/command.rb', line 147 def original_repo_root @original_repo_root ||= File.(ENV['TEST_RUNNER_REPO_ROOT'] || Dir.pwd) end |
#repo_root ⇒ Object (protected)
151 152 153 |
# File 'lib/test-runner/cli/command.rb', line 151 def repo_root @repository_source&.path || original_repo_root end |
#select_test_scripts(pattern) ⇒ Array<TestScript> (protected)
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/test-runner/cli/command.rb', line 120 def select_test_scripts(pattern) tsl = TestRunner::TestScriptList.new(system: opts['system'], test_config_path:, repo_root:) attr_filters = Cli::LabelFilters.new(opts['label']) tag_filters = Cli::TagFilters.new(opts['tag']) expr_filters = Array(opts['filter']).map { |expr| Cli::FilterExpression.new(expr) } tsl.matching(pattern).select do |ts| attr_filters.pass?(ts) \ && tag_filters.pass?(ts) \ && expr_filters.all? { |expr| expr.pass?(ts) } end end |
#state_dir ⇒ Object (protected)
134 135 136 |
# File 'lib/test-runner/cli/command.rb', line 134 def state_dir File.join(opts['state-dir'] || File.join(ENV['TMPDIR'] || '/tmp', 'os-test-runner')) end |
#test ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/test-runner/cli/command.rb', line 23 def test estimate = opts['prebuild-memory-per-job-mib'] if estimate && Integer(estimate) <= 0 raise ArgumentError, 'prebuild-memory-per-job-mib must be positive' end test_scripts = select_test_scripts(args[0]) puts 'The following test scripts will be run:' test_scripts.each { |t| puts " #{t.path}" } puts = { state_dir:, jobs: test_jobs(test_scripts), jobs_auto: jobs_auto?, max_memory_mib: opts['max-memory-mib'], max_shm_mib: opts['max-shm-mib'], max_cpus: opts['max-cpus'], memory_reserve_mib: opts['memory-reserve-mib'], shm_reserve_mib: opts['shm-reserve-mib'], cpu_reserve: opts['cpu-reserve'], memory_overcommit: opts['memory-overcommit'], shm_overcommit: opts['shm-overcommit'], cpu_overcommit: opts['cpu-overcommit'], resource_refresh_interval: opts['resource-refresh-interval'], status_interval: opts['status-interval'], verbose: opts['verbose'], default_timeout: opts['timeout'], stop_on_failure: opts['stop-on-failure'], destructive: opts['destructive'], recreate_disks: opts['fresh'], system: opts['system'], test_config_path:, repo_root: } results = if opts['prebuild'] pool = ResourcePool.() Prebuild.new( test_scripts, resource_pool: pool, state_dir:, memory_per_job_mib: opts['prebuild-memory-per-job-mib'] || Prebuild::DEFAULT_MEMORY_PER_JOB_MIB, system: opts['system'], test_config_path:, repo_root: ).open do |configs| pool.refresh_capacity Executor.new(test_scripts, **, resource_pool: pool, prepared_configs: configs).run end else Executor.new(test_scripts, **).run end return unless results.detect(&:unexpected_result?) raise 'one or more tests did not have expected results' end |
#test_config_path ⇒ Object (protected)
155 156 157 158 159 |
# File 'lib/test-runner/cli/command.rb', line 155 def test_config_path return opts['test-config'] unless @repository_source @repository_source.resolve_path(opts['test-config']) end |
#test_jobs(test_scripts) ⇒ Object (protected)
106 107 108 109 110 111 112 113 |
# File 'lib/test-runner/cli/command.rb', line 106 def test_jobs(test_scripts) return test_scripts.map(&:test).uniq.length if jobs_auto? ret = Integer(opts['jobs']) raise 'jobs must be positive' if ret <= 0 ret end |
#with_repository_environment(source_path) ⇒ Object (protected)
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/test-runner/cli/command.rb', line 161 def with_repository_environment(source_path) original_env = ENV.fetch('TEST_RUNNER_REPO_ROOT', nil) original_config = ENV.fetch('VPSADMINOS_CONFIG', nil) ENV['TEST_RUNNER_REPO_ROOT'] = source_path if original_config && !original_config.empty? && @repository_source ENV['VPSADMINOS_CONFIG'] = @repository_source.resolve_path(original_config) end yield ensure if original_env.nil? ENV.delete('TEST_RUNNER_REPO_ROOT') else ENV['TEST_RUNNER_REPO_ROOT'] = original_env end if original_config.nil? ENV.delete('VPSADMINOS_CONFIG') else ENV['VPSADMINOS_CONFIG'] = original_config end end |
#with_repository_source ⇒ Object (protected)
138 139 140 141 142 143 144 145 |
# File 'lib/test-runner/cli/command.rb', line 138 def with_repository_source(&) RepositorySource.open(original_path: original_repo_root) do |source| @repository_source = source with_repository_environment(source.path, &) ensure @repository_source = nil end end |