Best Parallel_tests_ruby code snippet using ParallelTests.Test.tests_in_groups
runner.rb
Source:runner.rb  
...36        group_opts[:runtime_log] = "tmp/turbo_rspec_runtime.log"37      else38        group_opts[:group_by] = :filesize39      end40      tests_in_groups =41        ParallelTests::RSpec::Runner.tests_in_groups(42          @files,43          @num_processes,44          **group_opts,45        )46      setup_tmp_dir47      subprocess_opts = {48        record_runtime: use_runtime_info49      }50      start_multisite_subprocess(@files, **subprocess_opts)51      tests_in_groups.each_with_index do |tests, process_id|52        start_regular_subprocess(tests, process_id + 1, **subprocess_opts)53      end54      handle_messages55      @reporter.finish56      @threads.each(&:join)57      @reporter.failed_examples.empty?58    end59    protected60    def check_for_migrations61      config =62        ActiveRecord::Base63          .configurations["test"]64          .merge("database" => "discourse_test_1")65      ActiveRecord::Tasks::DatabaseTasks.migrations_paths = ['db/migrate', 'db/post_migrate']...parallel_tests_spec.rb
Source:parallel_tests_spec.rb  
...3  def size_of(group)4    group.inject(0) { |sum, test| sum += File.stat(test).size }5  end6  7  describe :tests_in_groups_of do8    before :all do9      system "rm -rf #{FAKE_RAILS_ROOT}; mkdir -p #{FAKE_RAILS_ROOT}/test/temp"10      1.upto(100) do |i|11        size = 100 * i12        File.open("#{FAKE_RAILS_ROOT}/test/temp/x#{i}_test.rb", 'w') { |f| f.puts 'x' * size }13      end14    end15    it "finds all tests" do16      found = ParallelTests.tests_in_groups(FAKE_RAILS_ROOT, 1)17      all = [ Dir["#{FAKE_RAILS_ROOT}/test/**/*_test.rb"] ]18      (found.flatten - all.flatten).should == []19    end20    it "partitions them into groups by equal size" do21      groups = ParallelTests.tests_in_groups(FAKE_RAILS_ROOT, 2)22      groups.size.should == 223      group0 = size_of(groups[0])24      group1 = size_of(groups[1])25      diff = group0 * 0.126      group0.should be_close(group1, diff)27    end28    29    it 'should partition correctly with a group size of 4' do30      groups = ParallelTests.tests_in_groups(FAKE_RAILS_ROOT, 4)31      groups.size.should == 432      group_size = size_of(groups[0])33      diff = group_size * 0.1     34      group_size.should be_close(size_of(groups[1]), diff)35      group_size.should be_close(size_of(groups[2]), diff)36      group_size.should be_close(size_of(groups[3]), diff)37    end38    it 'should partition correctly with an uneven group size' do39      groups = ParallelTests.tests_in_groups(FAKE_RAILS_ROOT, 3)40      groups.size.should == 341      group_size = size_of(groups[0])42      diff = group_size * 0.143      group_size.should be_close(size_of(groups[1]), diff)44      group_size.should be_close(size_of(groups[2]), diff)45    end46  end47  describe :run_tests do48    it "uses TEST_ENV_NUMBER=blank when called for process 0" do49      ParallelTests.should_receive(:open).with{|x|x=~/TEST_ENV_NUMBER= /}.and_return mock(:gets=>false)50      ParallelTests.run_tests(['xxx'],0)51    end52    it "uses TEST_ENV_NUMBER=2 when called for process 1" do53      ParallelTests.should_receive(:open).with{|x| x=~/TEST_ENV_NUMBER=2/}.and_return mock(:gets=>false)...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
