specjour 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.1.10
data/bin/specjour CHANGED
@@ -20,8 +20,7 @@ optparse = OptionParser.new do |opts|
20
20
  end
21
21
 
22
22
  opts.on('--do-work OPTIONS', Array, 'INTERNAL USE ONLY') do |args|
23
- specs_to_run = args[3..-1]
24
- options[:worker_args] = args[0], args[1], args[2], specs_to_run
23
+ options[:worker_args] = args[0], args[1], args[2]
25
24
  end
26
25
 
27
26
  opts.on_tail('-v', '--version', 'Show the version of specjour') do
@@ -42,15 +42,7 @@ module Specjour
42
42
  end
43
43
 
44
44
  def dispatch_work
45
- distributable_specs = all_specs.among(worker_size)
46
- last_index = 0
47
- managers.each_with_index do |manager, index|
48
- manager.specs_to_run = Array.new(manager.worker_size) do |i|
49
- distributable_specs[last_index + i]
50
- end
51
- last_index += manager.worker_size
52
- manager_threads << Thread.new(manager) {|m| m.dispatch}
53
- end
45
+ command_managers(true) { |m| m.dispatch }
54
46
  end
55
47
 
56
48
  def drb_start
@@ -87,7 +79,11 @@ module Specjour
87
79
  end
88
80
 
89
81
  def printer
90
- @printer ||= Printer.new.start
82
+ @printer ||= begin
83
+ p = Printer.new
84
+ p.specs_to_run = all_specs
85
+ p.start
86
+ end
91
87
  end
92
88
 
93
89
  def project_name
@@ -12,7 +12,7 @@ module Specjour
12
12
 
13
13
  def initialize(options, output)
14
14
  @options = options
15
- @output = output.extend Specjour::Protocol
15
+ @output = output
16
16
  @failing_messages = []
17
17
  @passing_messages = []
18
18
  @pending_messages = []
@@ -41,8 +41,7 @@ module Specjour
41
41
  @example_count = example_count
42
42
  @failure_count = failure_count
43
43
  @pending_count = pending_count
44
- output.puts [:worker_summary=, to_hash]
45
- output.flush
44
+ output.send_message(:worker_summary=, to_hash)
46
45
  end
47
46
 
48
47
  def dump_pending
@@ -37,7 +37,7 @@ module Specjour
37
37
  bonjour_service.stop
38
38
  (1..worker_size).each do |index|
39
39
  worker_pids << fork do
40
- exec("specjour --batch-size #{batch_size} --do-work #{project_path},#{dispatcher_uri},#{index},#{specs_to_run[index - 1].join(',')}")
40
+ exec("specjour --batch-size #{batch_size} --do-work #{project_path},#{dispatcher_uri},#{index}")
41
41
  Kernel.exit!
42
42
  end
43
43
  end
@@ -55,7 +55,7 @@ module Specjour
55
55
 
56
56
  def drb_start
57
57
  DRb.start_service nil, self
58
- Kernel.puts "Manager started at #{drb_uri}"
58
+ puts "Manager started at #{drb_uri}"
59
59
  at_exit { DRb.stop_service }
60
60
  end
61
61
 
@@ -66,7 +66,7 @@ module Specjour
66
66
  protected
67
67
 
68
68
  def cmd(command)
69
- Kernel.puts command
69
+ puts command
70
70
  system command
71
71
  end
72
72
 
@@ -3,8 +3,7 @@ module Specjour
3
3
  include Protocol
4
4
  RANDOM_PORT = 0
5
5
 
6
- attr_reader :completed_workers
7
- attr_accessor :worker_size
6
+ attr_accessor :worker_size, :specs_to_run, :completed_workers
8
7
 
9
8
  def initialize
10
9
  super(
@@ -19,34 +18,43 @@ module Specjour
19
18
  end
20
19
 
21
20
  def serve(client)
21
+ client.extend Protocol
22
22
  client.each(TERMINATOR) do |data|
23
- process load_object(data)
23
+ process load_object(data), client
24
24
  end
25
25
  end
26
26
 
27
- def worker_summary=(summary)
27
+ def ready(client)
28
+ client.print specs_to_run.shift
29
+ client.flush
30
+ end
31
+
32
+ def done(client)
33
+ self.completed_workers += 1
34
+ end
35
+
36
+ def worker_summary=(client, summary)
28
37
  report.add(summary)
29
38
  end
30
39
 
31
40
  protected
32
41
 
33
42
  def disconnecting(client_port)
34
- @completed_workers += 1
35
43
  if completed_workers == worker_size
36
44
  stop
37
45
  end
38
46
  end
39
47
 
40
48
  def log(msg)
41
- #noop
49
+ # noop
42
50
  end
43
51
 
44
- def process(message)
52
+ def process(message, client)
45
53
  if message.is_a?(String)
46
54
  $stdout.print message
47
55
  $stdout.flush
48
56
  elsif message.is_a?(Array)
49
- send(message.first, message[1])
57
+ send(message.first, client, *message[1..-1])
50
58
  end
51
59
  end
52
60
 
@@ -1,21 +1,27 @@
1
1
  module Specjour
2
2
  module Protocol
3
3
  TERMINATOR = "|ruojceps|"
4
+ TERMINATOR_REGEXP = /#{TERMINATOR}$/
4
5
 
5
- def puts(arg)
6
- print(arg << "\n")
6
+ def dump_object(data)
7
+ Marshal.dump(data) << TERMINATOR
8
+ end
9
+
10
+ def load_object(data)
11
+ Marshal.load(data.sub(TERMINATOR_REGEXP, ''))
7
12
  end
8
13
 
9
14
  def print(arg)
10
15
  super dump_object(arg)
11
16
  end
12
17
 
13
- def dump_object(data)
14
- Marshal.dump(data) << TERMINATOR
18
+ def puts(arg)
19
+ print(arg << "\n")
15
20
  end
16
21
 
17
- def load_object(data)
18
- Marshal.load(data.sub(/#{TERMINATOR}$/, ''))
22
+ def send_message(method_name, *args)
23
+ print([method_name, *args])
24
+ flush
19
25
  end
20
26
  end
21
27
  end
@@ -1,45 +1,59 @@
1
1
  module Specjour
2
2
  class Worker
3
- attr_accessor :dispatcher_uri
3
+ include Protocol
4
+ attr_accessor :printer_uri
4
5
  attr_reader :project_path, :specs_to_run, :number, :batch_size
5
6
 
6
- def initialize(project_path, dispatcher_uri, number, specs_to_run, batch_size)
7
+ def initialize(project_path, printer_uri, number, batch_size)
7
8
  @project_path = project_path
8
9
  @specs_to_run = specs_to_run
9
10
  @number = number.to_i
10
11
  @batch_size = batch_size.to_i
11
- self.dispatcher_uri = dispatcher_uri
12
+ self.printer_uri = printer_uri
13
+ GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)
14
+ DistributedFormatter.batch_size = batch_size
15
+ Dir.chdir(project_path)
16
+ set_env_variables
12
17
  end
13
18
 
14
- def dispatcher_uri=(val)
15
- @dispatcher_uri = URI.parse(val)
19
+ def printer_uri=(val)
20
+ @printer_uri = URI.parse(val)
16
21
  end
17
22
 
18
23
  def run
19
- puts "Running #{specs_to_run.size} spec files..."
20
- GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)
21
- DistributedFormatter.batch_size = batch_size
22
- Dir.chdir(project_path) do
23
- set_env_variables
24
- options = Spec::Runner::OptionParser.parse(
25
- rspec_options,
26
- STDERR,
27
- dispatcher
28
- )
29
- Spec::Runner.use options
30
- options.run_examples
31
- Spec::Runner.options.instance_variable_set(:@examples_run, true)
24
+ printer.send_message(:ready)
25
+ while !printer.closed? && data = printer.gets(TERMINATOR)
26
+ spec = load_object(data)
27
+ if spec
28
+ run_spec spec
29
+ printer.send_message(:ready)
30
+ else
31
+ printer.send_message(:done)
32
+ printer.close
33
+ end
32
34
  end
33
35
  end
34
36
 
35
37
  protected
36
38
 
37
- def dispatcher
38
- @dispatcher ||= TCPSocket.open dispatcher_uri.host, dispatcher_uri.port
39
+ def printer
40
+ @printer ||= printer_connection
41
+ end
42
+
43
+ def printer_connection
44
+ TCPSocket.open(printer_uri.host, printer_uri.port).extend Protocol
39
45
  end
40
46
 
41
- def rspec_options
42
- %w(--format=Specjour::DistributedFormatter) + specs_to_run
47
+ def run_spec(spec)
48
+ Kernel.puts "Running #{spec}"
49
+ options = Spec::Runner::OptionParser.parse(
50
+ ['--format=Specjour::DistributedFormatter', spec],
51
+ $stderr,
52
+ printer_connection
53
+ )
54
+ Spec::Runner.use options
55
+ options.run_examples
56
+ Spec::Runner.options.instance_variable_set(:@examples_run, true)
43
57
  end
44
58
 
45
59
  def set_env_variables
data/lib/specjour.rb CHANGED
@@ -18,5 +18,5 @@ module Specjour
18
18
  autoload :RsyncDaemon, 'specjour/rsync_daemon'
19
19
  autoload :Worker, 'specjour/worker'
20
20
 
21
- VERSION = "0.1.9".freeze
21
+ VERSION = "0.1.10".freeze
22
22
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 9
9
- version: 0.1.9
8
+ - 10
9
+ version: 0.1.10
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sandro Turriate
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-26 00:00:00 -04:00
17
+ date: 2010-04-05 00:00:00 -04:00
18
18
  default_executable: specjour
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency