Class: ActiveSupport::Testing::Parallelization::Server

Inherits:
Object
  • Object
show all
Includes:
DRb::DRbUndumped
Defined in:
lib/active_support/testing/parallelization/server.rb

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



14
15
16
17
18
# File 'lib/active_support/testing/parallelization/server.rb', line 14

def initialize
  @queue = Queue.new
  @active_workers = Concurrent::Map.new
  @in_flight = Concurrent::Map.new
end

Instance Method Details

#<<(o) ⇒ Object



31
32
33
34
# File 'lib/active_support/testing/parallelization/server.rb', line 31

def <<(o)
  o[2] = DRbObject.new(o[2]) if o
  @queue << o
end

#active_workers?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/active_support/testing/parallelization/server.rb', line 51

def active_workers?
  @active_workers.size > 0
end

#interruptObject



55
56
57
# File 'lib/active_support/testing/parallelization/server.rb', line 55

def interrupt
  @queue.clear
end

#popObject



36
37
38
39
40
41
# File 'lib/active_support/testing/parallelization/server.rb', line 36

def pop
  if test = @queue.pop
    @in_flight[[test[0].to_s, test[1]]] = test
    test
  end
end

#record(reporter, result) ⇒ Object

Raises:

  • (DRb::DRbConnError)


20
21
22
23
24
25
26
27
28
29
# File 'lib/active_support/testing/parallelization/server.rb', line 20

def record(reporter, result)
  raise DRb::DRbConnError if result.is_a?(DRb::DRbUnknown)

  @in_flight.delete([result.klass, result.name])

  reporter.synchronize do
    reporter.prerecord(PrerecordResultClass.new(result.klass), result.name)
    reporter.record(result)
  end
end

#shutdownObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/active_support/testing/parallelization/server.rb', line 59

def shutdown
  # Wait for initial queue to drain
  while @queue.length != 0
    sleep 0.1
  end

  @queue.close

  # Wait until all workers have finished
  while active_workers?
    sleep 0.1
  end

  @in_flight.values.each do |(klass, name, reporter)|
    result = Minitest::Result.from(klass.new(name))
    error = RuntimeError.new("result not reported")
    error.set_backtrace([""])
    result.failures << Minitest::UnexpectedError.new(error)
    reporter.synchronize do
      reporter.record(result)
    end
  end
end

#start_worker(worker_id) ⇒ Object



43
44
45
# File 'lib/active_support/testing/parallelization/server.rb', line 43

def start_worker(worker_id)
  @active_workers[worker_id] = true
end

#stop_worker(worker_id) ⇒ Object



47
48
49
# File 'lib/active_support/testing/parallelization/server.rb', line 47

def stop_worker(worker_id)
  @active_workers.delete(worker_id)
end