prspec 0.2.1 → 0.2.2

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.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/prspec.rb +40 -32
  3. metadata +5 -10
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWE4YTYyMjc3YmY1MjM2NWQzM2E0OWFkZGM1YzJlMjY0NzI1NDViYw==
5
+ data.tar.gz: !binary |-
6
+ N2Y3ZmRjOTg2OTNjYTJmYmQ4NjA5ZjdkZjZjMmUxMDgzMmI1ZWI4ZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YTcxOGEyYmM2NWFjMWQwNjdiZmZmOGI4NDFhYTIwODQ3MGM4MzE2MGViM2U2
10
+ N2EyNGY2NGM4MTRiYzc0ZWMxZmY2NTI0ZWFmNGU0ZmI5M2IwOTA1YjQyYTIz
11
+ M2U4MDI2ZTEwODhjZTVkZGEzYzBmZWRkZjc5NDQ0MGFmYTQ3Yzg=
12
+ data.tar.gz: !binary |-
13
+ MWQ0ZDc0NTgyMzU1YTUzYTQwMWI0ZGJkMmY0NjJjNmI1MWI5MmQ5Zjg0NmQ2
14
+ Yjc1M2NjMzRkMTUyYjQzZThhNmEyM2U1MGM4NGI0ODBlNjQwMzk1NDljNjM5
15
+ ZTUyMjFhZjZkZWQ0MWI5ZmIyNmMwODE2MDhjNWQwOTU4NTg3Mjk=
data/lib/prspec.rb CHANGED
@@ -2,7 +2,9 @@ require 'thread'
2
2
  require 'optparse'
3
3
  require 'log4r'
4
4
  require 'parallel'
5
+ require 'yaml'
5
6
  require 'tempfile'
7
+ require 'fileutils'
6
8
  include Log4r
7
9
 
8
10
  $log = Logger.new('prspec')
@@ -22,10 +24,15 @@ else
22
24
  end
23
25
 
24
26
  class PRSpec
25
- attr_accessor :num_threads, :processes, :tests
27
+ attr_accessor :num_threads, :processes, :tests, :output
26
28
  SPEC_FILE_FILTER = '_spec.rb'
29
+ INFO_FILE = ".prspec"
27
30
 
28
31
  def initialize(args)
32
+ @output = ''
33
+ # create tracking file
34
+ yml = { :running_threads => 0 }
35
+ File.open(INFO_FILE, 'w') { |f| f.write yml.to_yaml }
29
36
  if (!args.nil? && args.length > 0 && !args[0].nil?)
30
37
  opts = parse_args(args)
31
38
  if (!opts[:help])
@@ -46,6 +53,8 @@ class PRSpec
46
53
  begin_run(@processes, opts)
47
54
  end
48
55
  end
56
+ ensure
57
+ FileUtils.remove_file(INFO_FILE, :force => true) if File.exists?(INFO_FILE)
49
58
  end
50
59
 
51
60
  def parse_args(args)
@@ -53,7 +62,7 @@ class PRSpec
53
62
  options = {
54
63
  :dir=>'.',
55
64
  :path=>'spec',
56
- :thread_count=>get_number_of_threads,
65
+ :thread_count=>get_number_of_processors,
57
66
  :test_mode=>false,
58
67
  :help=>false,
59
68
  :excludes=>nil,
@@ -127,26 +136,14 @@ class PRSpec
127
136
  return options
128
137
  end
129
138
 
130
- def get_number_of_threads
139
+ def get_number_of_processors
131
140
  count = Parallel.processor_count
132
141
  return count
133
142
  end
134
143
 
135
144
  def self.get_number_of_running_threads
136
- cmd = "ps -ef"
137
- if (PRSpec.is_windows?)
138
- cmd = "wmic process get commandline"
139
- end
140
- result = `#{cmd}`
141
- count = 0
142
- lines = result.split("\n")
143
- lines.each do |line|
144
- if (line.include?('TEST_ENV_NUMBER='))
145
- count += 1
146
- end
147
- end
148
- $log.debug "Found #{count} occurrances of TEST_ENV_NUMBER"
149
- return count
145
+ prspec_info = YAML.load_file(INFO_FILE)
146
+ return prspec_info[:running_threads].to_i
150
147
  end
151
148
 
152
149
  def get_spec_tests(options)
@@ -248,6 +245,7 @@ class PRSpec
248
245
  def begin_run(processes, options)
249
246
  if (!processes.nil? && processes.length > 0)
250
247
  $log.info "Starting all Child Processes..."
248
+ update_running_thread_count(processes.length)
251
249
  processes.each do |proc|
252
250
  if (proc.is_a?(PRSpecThread) && options.is_a?(Hash))
253
251
  proc.start unless options[:test_mode]
@@ -255,30 +253,38 @@ class PRSpec
255
253
  raise "Invalid datatype where PRSpecThread or Hash exepcted. Found: #{proc.class.to_s}, #{options.class.to_s}"
256
254
  end
257
255
  end
258
- $log.info "Processes started..."
259
- continue = true
260
- while continue
261
- continue = false
256
+ $log.info "All processes started..."
257
+ while processes.length > 0
262
258
  processes.each do |proc|
263
259
  if (!proc.done?) # confirm threads are running
264
- continue = true
265
260
  $log.debug "Thread#{proc.id}: alive..."
266
261
  else
267
262
  $log.debug "Thread#{proc.id}: done."
268
- # puts proc.output unless options[:quiet_mode]
269
- # proc.output = '' unless options[:quiet_mode] # prevent outputting same content multiple times
263
+ # collect thread output if in quiet mode
264
+ if (options[:quiet_mode])
265
+ @output << proc.output
266
+ end
267
+ processes.delete(proc) # remove from the array of processes so we don't count it again
268
+ update_running_thread_count(processes.length)
270
269
  end
271
270
  end
272
- if (continue)
273
- sleep(5) # wait a bit for processes to run and then re-check their status
274
- end
271
+ sleep 0.5 # wait half a second for processes to run and then re-check their status
275
272
  end
276
- $log.info "Processes complete."
273
+ $log.info "All processes complete."
277
274
  else
278
275
  raise "Invalid input passed to method: 'processes' must be a valid Array of PRSpecThread objects"
279
276
  end
280
277
  end
281
278
 
279
+ def update_running_thread_count(count)
280
+ (file = File.new(INFO_FILE,'w')).flock(File::LOCK_EX)
281
+ yml = { :running_threads => count }
282
+ file.write yml.to_yaml
283
+ ensure
284
+ file.flock(File::LOCK_UN)
285
+ file.close
286
+ end
287
+
282
288
  def running?
283
289
  @processes.each do |proc|
284
290
  if (!proc.done?)
@@ -308,8 +314,10 @@ class PRSpecThread
308
314
  @env = environment
309
315
  @args = args
310
316
  @output = ''
311
- @out = "prspec-t-#{@id}.out"
312
- @err = "prspec-t-#{@id}.err"
317
+ @out = Tempfile.new("prspec-t-#{@id}.out").path
318
+ $log.debug("Thread#{@id} @out file: #{@out}")
319
+ @err = Tempfile.new("prspec-t-#{@id}.err").path
320
+ $log.debug("Thread#{@id} @err file: #{@err}")
313
321
  end
314
322
 
315
323
  def start
@@ -350,8 +358,8 @@ class PRSpecThread
350
358
  @thread.sleep
351
359
  @thread.kill
352
360
  @thread = nil
353
- File.delete(@out) unless !File.exist?(@out)
354
- File.delete(@err) unless !File.exist?(@err)
361
+ FileUtils.remove_file(@out, :force => true) unless !File.exist?(@out)
362
+ FileUtils.remove_file(@err, :force => true) unless !File.exist?(@err)
355
363
  end
356
364
 
357
365
  def get_exports
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jason Holt Smith
@@ -14,7 +13,6 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: log4r
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: parallel
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -55,26 +50,26 @@ files:
55
50
  homepage: https://github.com/bicarbon8/prspec.git
56
51
  licenses:
57
52
  - MIT
53
+ metadata: {}
58
54
  post_install_message:
59
55
  rdoc_options: []
60
56
  require_paths:
61
57
  - lib
62
58
  required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
59
  requirements:
65
60
  - - ! '>='
66
61
  - !ruby/object:Gem::Version
67
62
  version: '0'
68
63
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
64
  requirements:
71
65
  - - ! '>='
72
66
  - !ruby/object:Gem::Version
73
67
  version: '0'
74
68
  requirements: []
75
69
  rubyforge_project:
76
- rubygems_version: 1.8.28
70
+ rubygems_version: 2.2.1
77
71
  signing_key:
78
- specification_version: 3
72
+ specification_version: 4
79
73
  summary: Parallel rspec execution
80
74
  test_files: []
75
+ has_rdoc: