How to use runtimes method of ParallelTests.Test Package

Best Parallel_tests_ruby code snippet using ParallelTests.Test.runtimes

runner.rb

Source:runner.rb Github

copy

Full Screen

...39 tests.map! { |t| [t, 1] }40 when :filesize41 sort_by_filesize(tests)42 when :runtime43 sort_by_runtime(tests, runtimes(tests, options), options.merge(allowed_missing: (options[:allowed_missing_percent] || 50) / 100.0))44 when nil45 # use recorded test runtime if we got enough data46 runtimes = runtimes(tests, options) rescue []47 if runtimes.size * 1.5 > tests.size48 puts "Using recorded test runtime"49 sort_by_runtime(tests, runtimes)50 else51 sort_by_filesize(tests)52 end53 else54 raise ArgumentError, "Unsupported option #{options[:group_by]}"55 end56 tests57 end58 def execute_command(cmd, process_number, num_processes, options)59 env = (options[:env] || {}).merge(60 "TEST_ENV_NUMBER" => test_env_number(process_number, options).to_s,61 "PARALLEL_TEST_GROUPS" => num_processes.to_s,62 "PARALLEL_PID_FILE" => ParallelTests.pid_file_path,63 )64 cmd = "nice #{cmd}" if options[:nice]65 cmd = "#{cmd} 2>&1" if options[:combine_stderr]66 puts cmd if options[:verbose] && !options[:serialize_stdout]67 execute_command_and_capture_output(env, cmd, options)68 end69 def execute_command_and_capture_output(env, cmd, options)70 pid = nil71 output = IO.popen(env, cmd) do |io|72 pid = io.pid73 ParallelTests.pids.add(pid)74 capture_output(io, env, options)75 end76 ParallelTests.pids.delete(pid) if pid77 exitstatus = $?.exitstatus78 seed = output[/seed (\d+)/,1]79 output = [cmd, output].join("\n") if options[:verbose] && options[:serialize_stdout]80 {:stdout => output, :exit_status => exitstatus, :command => cmd, :seed => seed}81 end82 def find_results(test_output)83 test_output.lines.map do |line|84 line.chomp!85 line.gsub!(/\e\[\d+m/, '') # remove color coding86 next unless line_is_result?(line)87 line88 end.compact89 end90 def test_env_number(process_number, options={})91 if process_number == 0 && !options[:first_is_1]92 ''93 else94 process_number + 195 end96 end97 def summarize_results(results)98 sums = sum_up_results(results)99 sums.sort.map{|word, number| "#{number} #{word}#{'s' if number != 1}" }.join(', ')100 end101 # remove old seed and add new seed102 def command_with_seed(cmd, seed)103 clean = cmd.sub(/\s--seed\s+\d+\b/, '')104 "#{clean} --seed #{seed}"105 end106 protected107 def executable108 ENV['PARALLEL_TESTS_EXECUTABLE'] || determine_executable109 end110 def determine_executable111 "ruby"112 end113 def sum_up_results(results)114 results = results.join(' ').gsub(/s\b/,'') # combine and singularize results115 counts = results.scan(/(\d+) (\w+)/)116 counts.inject(Hash.new(0)) do |sum, (number, word)|117 sum[word] += number.to_i118 sum119 end120 end121 # read output of the process and print it in chunks122 def capture_output(out, env, options={})123 result = ""124 loop do125 begin126 read = out.readpartial(1000000) # read whatever chunk we can get127 if Encoding.default_internal128 read = read.force_encoding(Encoding.default_internal)129 end130 result << read131 unless options[:serialize_stdout]132 message = read133 message = "[TEST GROUP #{env['TEST_ENV_NUMBER']}] #{message}" if options[:prefix_output_with_test_env_number]134 $stdout.print message135 $stdout.flush136 end137 end138 end rescue EOFError139 result140 end141 def sort_by_runtime(tests, runtimes, options={})142 allowed_missing = options[:allowed_missing] || 1.0143 allowed_missing = tests.size * allowed_missing144 # set know runtime for each test145 tests.sort!146 tests.map! do |test|147 allowed_missing -= 1 unless time = runtimes[test]148 if allowed_missing < 0149 log = options[:runtime_log] || runtime_log150 raise "Runtime log file '#{log}' does not contain sufficient data to sort #{tests.size} test files, please update it."151 end152 [test, time]153 end154 if options[:verbose]155 puts "Runtime found for #{tests.count(&:last)} of #{tests.size} tests"156 end157 # fill gaps with unknown-runtime if given, average otherwise158 known, unknown = tests.partition(&:last)159 average = (known.any? ? known.map!(&:last).inject(:+) / known.size : 1)160 unknown_runtime = options[:unknown_runtime] || average161 unknown.each { |set| set[1] = unknown_runtime }162 end163 def runtimes(tests, options)164 log = options[:runtime_log] || runtime_log165 lines = File.read(log).split("\n")166 lines.each_with_object({}) do |line, times|167 test, _, time = line.rpartition(':')168 next unless test and time169 times[test] = time.to_f if tests.include?(test)170 end171 end172 def sort_by_filesize(tests)173 tests.sort!174 tests.map! { |test| [test, File.stat(test).size] }175 end176 def find_tests(tests, options = {})177 (tests || []).map do |file_or_folder|...

Full Screen

Full Screen

runtime_logger_test.rb

Source:runtime_logger_test.rb Github

copy

Full Screen

...30 @logger.log_runtime(test_case) { 'hello' }31 expected = "1.5 ParallelTests::FineGrainTest::RuntimeLoggerTest one\n"32 assert_equal expected, File.read(@file_name)33 end34 def test_log_runtime__should_append_runtimes_to_existing_ones35 File.write(@file_name, "1.5 ParallelTests::FineGrainTest::RuntimeLoggerTest one\n")36 test_case = TestCase.new(self.class, 'two')37 RuntimeLogger.stubs(:delta).returns(2.5)38 @logger.log_runtime(test_case) { 'hello' }39 expected = "1.5 ParallelTests::FineGrainTest::RuntimeLoggerTest one\n" \40 "2.5 ParallelTests::FineGrainTest::RuntimeLoggerTest two\n"41 assert_equal expected, File.read(@file_name)42 end43 def test_runtime__should_return_empty_when_file_empty44 result = @logger.runtimes45 assert result.empty?46 end47 def test_runtime__should_return_test_cases_to_times_from_file48 test_case_one = TestCase.new(self.class, 'one')49 test_case_two = TestCase.new(self.class, 'two')50 File.write(@file_name,51 "1.5 ParallelTests::FineGrainTest::RuntimeLoggerTest one\n" \52 "2.5 ParallelTests::FineGrainTest::RuntimeLoggerTest two\n")53 result = @logger.runtimes54 assert_equal 2, result.size55 assert_equal 1.5, result[test_case_one]56 assert_equal 2.5, result[test_case_two]57 end58 end59 end60end...

Full Screen

Full Screen

runtimes

Using AI Code Generation

copy

Full Screen

1ParallelTests::Test::RuntimeLogger.log('test.rb', 1.1)2ParallelTests::Test::RuntimeLogger.log('test.rb', 2.2)3ParallelTests::Test::RuntimeLogger.log('test.rb', 3.3)

Full Screen

Full Screen

runtimes

Using AI Code Generation

copy

Full Screen

1test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'])2test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'], :serialize_stdout => true)3test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'], :serialize_stdout => false)4test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'])5test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'], :serialize_stdout => true)6test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'], :serialize_stdout => false)7test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'])8test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'], :serialize_stdout => true)9test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'], :serialize_stdout => false)10test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'])11test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'], :serialize_stdout => true)12test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'], :serialize_stdout => false)13test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'])14test.run_tests(['test1.rb', 'test2.rb', 'test3.rb'], :serialize_stdout

Full Screen

Full Screen

runtimes

Using AI Code Generation

copy

Full Screen

1test.runtimes(:ms)2test.runtimes(:min)3test.runtimes(:hr)4test.runtimes(:day)5test.runtimes(:yr)6test.runtimes(2)7test.runtimes(3)8test.runtimes(4)9test.runtimes(5)10test.runtimes(6)11test.runtimes(7)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful