parallel_tests 2.15.0 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c475b70366d96f840ad6857d86c8ff9cfbf6bc5
4
- data.tar.gz: df7751a1d3d61172c1ef0a2ac4d7950f6232f910
3
+ metadata.gz: b379a6559260bc09ecbdf2f662561213b1f765d4
4
+ data.tar.gz: 7589375b613e87e4eab4753cc7694afb46d3de4b
5
5
  SHA512:
6
- metadata.gz: 79ffeb8fa61bb454ca5b7bef04fe66a2b8a071a376fff36f65f0fb84e23c0d1e8b3517ce8e51eacd8e88cbf34916a8495f118c6dc56b63efdcf183f7abd5bfcd
7
- data.tar.gz: 6c5a8844af6c3f9e1b0ed2dac1426593bca85139ff16dc0aa0624c923b6a765011e861c20aa66a212e6f161e772171531360a7e4843109dcc81d798cfef0e21b
6
+ metadata.gz: 8531b811305f22ae1206776d2068fb99699f65a0458376036b1efcb661176032d2ae46068f6c6d1a964dfa9066e627ff7698de14b43112bae834f8639bc3fe18
7
+ data.tar.gz: cbd83e152eb227ad954fadd7b97c85d3c7209d7cadf142add277e55c2c155ae95edfd0afc6b5917b04ad1ed4fbbb3a75a4fbecc05d40dab601b0b4ba3c171e9a
data/Readme.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/parallel_tests.svg)](https://rubygems.org/gems/parallel_tests)
4
4
  [![Build Status](https://travis-ci.org/grosser/parallel_tests.svg)](https://travis-ci.org/grosser/parallel_tests/builds)
5
+ [![Build status](https://ci.appveyor.com/api/projects/status/708b1up4pqc34x3y?svg=true)](https://ci.appveyor.com/project/grosser/parallel-tests)
5
6
 
6
7
  Speedup Test::Unit + RSpec + Cucumber + Spinach by running parallel on multiple CPU cores.<br/>
7
8
  ParallelTests splits tests into even groups (by number of lines or runtime) and runs each group in a single process with its own database.
@@ -4,17 +4,12 @@ require "rbconfig"
4
4
 
5
5
  module ParallelTests
6
6
  WINDOWS = (RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
7
- GREP_PROCESSES_COMMAND = \
8
- if WINDOWS
9
- "wmic process get commandline | findstr TEST_ENV_NUMBER | find /c \"TEST_ENV_NUMBER=\" 2>&1"
10
- else
11
- "ps -ef | grep [T]EST_ENV_NUMBER= 2>&1"
12
- end
13
7
  RUBY_BINARY = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
14
8
 
15
9
  autoload :CLI, "parallel_tests/cli"
16
10
  autoload :VERSION, "parallel_tests/version"
17
11
  autoload :Grouper, "parallel_tests/grouper"
12
+ autoload :Pids, "parallel_tests/pids"
18
13
 
19
14
  class << self
20
15
  def determine_number_of_processes(count)
@@ -25,6 +20,14 @@ module ParallelTests
25
20
  ].detect{|c| not c.to_s.strip.empty? }.to_i
26
21
  end
27
22
 
23
+ def pids
24
+ @pids ||= Pids.new(pid_file_path)
25
+ end
26
+
27
+ def pid_file_path
28
+ ENV['PARALLEL_PID_FILE'] ||= Tempfile.new('parallel-tests-pidfile').path
29
+ end
30
+
28
31
  # copied from http://github.com/carlhuda/bundler Bundler::SharedHelpers#find_gemfile
29
32
  def bundler_enabled?
30
33
  return true if Object.const_defined?(:Bundler)
@@ -70,11 +73,8 @@ module ParallelTests
70
73
  sleep 1 until number_of_running_processes <= 1
71
74
  end
72
75
 
73
- # Fun fact: this includes the current process if it's run via parallel_tests
74
76
  def number_of_running_processes
75
- result = `#{GREP_PROCESSES_COMMAND}`
76
- raise "Could not grep for processes -> #{result}" if result.strip != "" && !$?.success?
77
- result.split("\n").size
77
+ pids.count
78
78
  end
79
79
 
80
80
  # real time even if someone messed with timecop in tests
@@ -28,6 +28,7 @@ module ParallelTests
28
28
  Tempfile.open 'parallel_tests-lock' do |lock|
29
29
  progress_indicator = simulate_output_for_ci if options[:serialize_stdout]
30
30
 
31
+ ParallelTests.pids # setup the class vars here so we dont initialize in the threads
31
32
  Parallel.map(items, :in_threads => num_processes) do |item|
32
33
  result = yield(item)
33
34
  if progress_indicator && progress_indicator.alive?
@@ -0,0 +1,60 @@
1
+ require 'tempfile'
2
+ require 'json'
3
+
4
+ module ParallelTests
5
+ class Pids
6
+ attr_reader :pids, :file_path, :mutex
7
+
8
+ def initialize(file_path)
9
+ @file_path = file_path
10
+ @mutex = Mutex.new
11
+ end
12
+
13
+ def add(pid)
14
+ pids << pid.to_i
15
+ save
16
+ end
17
+
18
+ def delete(pid)
19
+ pids.delete(pid.to_i)
20
+ save
21
+ end
22
+
23
+ def count
24
+ read
25
+ pids.count
26
+ end
27
+
28
+ private
29
+
30
+ def pids
31
+ @pids ||= []
32
+ end
33
+
34
+ def all
35
+ read
36
+ pids
37
+ end
38
+
39
+ def clear
40
+ @pids = []
41
+ save
42
+ end
43
+
44
+ def read
45
+ sync do
46
+ contents = IO.read(file_path)
47
+ return if contents.empty?
48
+ @pids = JSON.parse(contents)
49
+ end
50
+ end
51
+
52
+ def save
53
+ sync { IO.write(file_path, pids.to_json) }
54
+ end
55
+
56
+ def sync
57
+ mutex.synchronize { yield }
58
+ end
59
+ end
60
+ end
@@ -71,8 +71,9 @@ module ParallelTests
71
71
 
72
72
  def execute_command(cmd, process_number, num_processes, options)
73
73
  env = (options[:env] || {}).merge(
74
- "TEST_ENV_NUMBER" => test_env_number(process_number, options),
75
- "PARALLEL_TEST_GROUPS" => num_processes
74
+ "TEST_ENV_NUMBER" => test_env_number(process_number, options).to_s,
75
+ "PARALLEL_TEST_GROUPS" => num_processes.to_s,
76
+ "PARALLEL_PID_FILE" => ParallelTests.pid_file_path,
76
77
  )
77
78
  cmd = "nice #{cmd}" if options[:nice]
78
79
  cmd = "#{cmd} 2>&1" if options[:combine_stderr]
@@ -84,18 +85,13 @@ module ParallelTests
84
85
  end
85
86
 
86
87
  def execute_command_and_capture_output(env, cmd, silence)
87
- # make processes descriptive / visible in ps -ef
88
- separator = (WINDOWS ? ' & ' : ';')
89
- exports = env.map do |k,v|
90
- if WINDOWS
91
- "(SET \"#{k}=#{v}\")"
92
- else
93
- "#{k}=#{v};export #{k}"
94
- end
95
- end.join(separator)
96
- cmd = "#{exports}#{separator}#{cmd}"
97
-
98
- output = open("|#{cmd}", "r") { |output| capture_output(output, silence) }
88
+ pid = nil
89
+ output = IO.popen(env, cmd) do |io|
90
+ pid = io.pid
91
+ ParallelTests.pids.add(pid)
92
+ capture_output(io, silence)
93
+ end
94
+ ParallelTests.pids.delete(pid) if pid
99
95
  exitstatus = $?.exitstatus
100
96
  seed = output[/seed (\d+)/,1]
101
97
 
@@ -1,3 +1,3 @@
1
1
  module ParallelTests
2
- VERSION = Version = '2.15.0'
2
+ VERSION = Version = '2.16.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel_tests
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.0
4
+ version: 2.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-02 00:00:00.000000000 Z
11
+ date: 2017-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel
@@ -50,6 +50,7 @@ files:
50
50
  - lib/parallel_tests/gherkin/runner.rb
51
51
  - lib/parallel_tests/gherkin/runtime_logger.rb
52
52
  - lib/parallel_tests/grouper.rb
53
+ - lib/parallel_tests/pids.rb
53
54
  - lib/parallel_tests/railtie.rb
54
55
  - lib/parallel_tests/rspec/failures_logger.rb
55
56
  - lib/parallel_tests/rspec/logger_base.rb