How to use unique_log method of ParallelTests.Test Package

Best Parallel_tests_ruby code snippet using ParallelTests.Test.unique_log


Source:runtime_logger.rb Github


Full Screen

...11 time = { result = yield }12 log(test, time)13 result14 end15 def unique_log16 lock do17 separator = "\n"18 groups = { |line| line.split(":") }.group_by(&:first)19 lines = do |file, times|20 time = "%.2f" % "#{file}:#{time}"22 end23 File.write(logfile, lines.join(separator) + separator)24 end25 end26 private27 # ensure folder exists + clean out previous log28 # this will happen in multiple processes, but should be roughly at the same time29 # so there should be no log message lost30 def prepare31 return if @@prepared32 @@prepared = true33 FileUtils.mkdir_p(File.dirname(logfile))34 File.write(logfile, '')35 end36 def log(test, time)37 return unless message = message(test, time)38 lock do39, 'a') { |f| f.puts message }40 end41 end42 def message(test, delta)43 return unless method = test.public_instance_methods(true).detect { |method| method =~ /^test_/ }44 filename = test.instance_method(method).source_location.first.sub("#{Dir.pwd}/", "")45 "#{filename}:#{delta}"46 end47 def lock48, 'r') do |f|49 begin50 f.flock File::LOCK_EX51 yield52 ensure53 f.flock File::LOCK_UN54 end55 end56 end57 def logfile58 ParallelTests::Test::Runner.runtime_log59 end60 end61 end62 end63end64if defined?(Minitest::Runnable) # Minitest 565 class << Minitest::Runnable66 prepend( do67 def run(*)68 ParallelTests::Test::RuntimeLogger.log_test_run(self) do69 super70 end71 end72 end)73 end74 class << Minitest75 prepend( do76 def run(*args)77 result = super78 ParallelTests::Test::RuntimeLogger.unique_log79 result80 end81 end)82 end83elsif defined?(MiniTest::Unit) # Minitest 484 MiniTest::Unit.class_eval do85 alias_method :_run_suite_without_runtime_log, :_run_suite86 def _run_suite(*args)87 ParallelTests::Test::RuntimeLogger.log_test_run(args.first) do88 _run_suite_without_runtime_log(*args)89 end90 end91 alias_method :_run_suites_without_runtime_log, :_run_suites92 def _run_suites(*args)93 result = _run_suites_without_runtime_log(*args)94 ParallelTests::Test::RuntimeLogger.unique_log95 result96 end97 end98else # Test::Unit99 require 'test/unit/testsuite'100 class ::Test::Unit::TestSuite101 alias_method :run_without_timing, :run102 def run(result, &block)103 test = tests.first104 if test.is_a? ::Test::Unit::TestSuite # all tests ?105 run_without_timing(result, &block)106 ParallelTests::Test::RuntimeLogger.unique_log107 else108 ParallelTests::Test::RuntimeLogger.log_test_run(test.class) do109 run_without_timing(result, &block)110 end111 end112 end113 end114end...

Full Screen

Full Screen


Using AI Code Generation


Full Screen


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:


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?