File: test_helper.rb

package info (click to toggle)
ruby-metriks 0.9.9.8-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 288 kB
  • sloc: ruby: 1,877; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 652 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'test/unit'
require 'pp'

# require 'mocha/setup'
require 'mocha/test_unit'

require 'metriks'

Thread.abort_on_exception = true

module ThreadHelper
  require 'thread'

  # Run the given block on n threads in parallel. Returns an array of the
  # return values of each thread's last invocation of block. Options:

  # :n: call block n times per thread. Default 1.
  def thread(threads = 2, opts = {})
    n = opts[:n] || 1
    results = []
   
    threads.times.map do |i|
      Thread.new do
        n.times do
          results[i] = yield i
        end
      end
    end.each do |thread|
      thread.join
    end
    
    results
  end
end