Module: Maxitest::Threads

Defined in:
lib/maxitest/threads.rb

Instance Method Summary collapse

Instance Method Details

#maxitest_extra_threadsObject

if setup crashes we do not return anything to make the initial error visible



29
30
31
# File 'lib/maxitest/threads.rb', line 29

def maxitest_extra_threads
  @maxitest_threads_before ? Thread.list - @maxitest_threads_before : []
end

#maxitest_kill_extra_threadsObject

also a helper methods for users



24
25
26
# File 'lib/maxitest/threads.rb', line 24

def maxitest_kill_extra_threads
  maxitest_extra_threads.map(&:kill).map(&:join)
end

#maxitest_wait_for_extra_threadsObject

also a helper methods for users



19
20
21
# File 'lib/maxitest/threads.rb', line 19

def maxitest_wait_for_extra_threads
  sleep 0.01 while maxitest_extra_threads.any?
end

#setupObject



5
6
7
8
# File 'lib/maxitest/threads.rb', line 5

def setup
  @maxitest_threads_before = Thread.list
  super
end

#teardownObject



10
11
12
13
14
15
16
# File 'lib/maxitest/threads.rb', line 10

def teardown
  super
  found = maxitest_extra_threads
  raise "Test left #{found.size} extra threads (#{found})" if found.any?
ensure
  maxitest_kill_extra_threads
end