11
12
13
14
15
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
|
# File 'lib/rspec_queue/server.rb', line 11
def dispatch(example_group_hash, report)
example_group_keys = example_group_hash.keys
while (example_group_keys.count > 0 || worker_uuids.count > 0) do
begin
socket = @server.accept
message = socket.gets.to_s.strip
case message
when "REGISTER"
worker_uid = generate_worker_uid
register_worker(worker_uid)
socket.puts worker_uid
when "GET_WORK"
if example_group_keys.count > 0
socket.puts example_group_keys.shift
else
socket.puts "SHUT_DOWN"
end
when "FINISH"
socket.puts "GET_UUID"
uuid = socket.gets.to_s.strip
worker_uuids.delete(uuid)
socket.puts "GET_RESULTS"
results = socket.gets.to_s.strip
json_results = JSON.parse(results, symbolize_names: true)
examples = json_results.select { |e| e[:status] == "passed" }
failed_examples = json_results.select { |e| e[:status] == "failed" }
pending_examples = json_results.select { |e| e[:status] == "pending" }
report.examples.push(*examples)
report.failed_examples.push(*failed_examples)
report.pending_examples.push(*pending_examples)
else
puts("unsupported: #{message}")
end
ensure
socket.close
end
end
end
|