Class: Nitra::Master

Inherits:
Object
  • Object
show all
Defined in:
lib/nitra/master.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, files = nil) ⇒ Master

Returns a new instance of Master.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/nitra/master.rb', line 4

def initialize(configuration, files = nil)
  @configuration = configuration
  @frameworks = configuration.frameworks
  if @frameworks.any?
    load_files_from_framework_list
  else
    map_files_to_frameworks(files)
  end
  @current_framework = @frameworks.shift
  @configuration.framework = @current_framework
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



2
3
4
# File 'lib/nitra/master.rb', line 2

def configuration
  @configuration
end

#current_frameworkObject (readonly)

Returns the value of attribute current_framework.



2
3
4
# File 'lib/nitra/master.rb', line 2

def current_framework
  @current_framework
end

#filesObject (readonly)

Returns the value of attribute files.



2
3
4
# File 'lib/nitra/master.rb', line 2

def files
  @files
end

#frameworksObject (readonly)

Returns the value of attribute frameworks.



2
3
4
# File 'lib/nitra/master.rb', line 2

def frameworks
  @frameworks
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/nitra/master.rb', line 16

def run
  return if files_remaining == 0

  progress = Nitra::Progress.new
  progress.file_count = files_remaining
  formatter = Nitra::Formatter.new(progress, configuration)

  runners = []

  if configuration.process_count > 0
    client, runner = Nitra::Channel.pipe
    fork do
      runner.close
      Nitra::Runner.new(configuration, client, "A").run
    end
    client.close
    runners << runner
  end

  slave = Nitra::Slave::Client.new(configuration)
  runners += slave.connect

  formatter.start

  while runners.length > 0
    Nitra::Channel.read_select(runners).each do |channel|
      if data = channel.read
        case data["command"]
        when "next"
          if files_remaining == 0
            channel.write "command" => "drain"
          elsif data["framework"] == current_framework
            channel.write "command" => "file", "filename" => next_file
          else
            channel.write "command" => "framework", "framework" => current_framework
          end

        when "result"
          examples = data["example_count"] || 0
          failures = data["failure_count"] || 0
          failure = data["return_code"].to_i != 0
          progress.file_progress(examples, failures, failure, data["text"])
          formatter.print_progress

        when "error"
          progress.fail("ERROR " + data["process"] + " " + data["text"])
          formatter.progress
          runners.delete channel

        when "debug"
          if configuration.debug
            puts "[DEBUG] #{data["text"]}"
          end

        when "stdout"
          if configuration.debug
            puts "STDOUT for #{data["process"]} #{data["filename"]}:\n#{data["text"]}" unless data["text"].empty?
          end
        end
      else
        runners.delete channel
      end
    end
  end

  debug "waiting for all children to exit..."
  Process.waitall

  formatter.finish

  !$aborted && progress.files_completed == progress.file_count && progress.failure_count.zero? && !progress.failure
end