Module: Maxitest::Threads

Defined in:
lib/maxitest/threads.rb

Instance Method Summary collapse

Instance Method Details

#maxitest_extra_threadsObject



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

def maxitest_extra_threads
  Thread.list - @maxitest_threads_before
end

#maxitest_kill_extra_threadsObject

also a helper methods for users



26
27
28
# File 'lib/maxitest/threads.rb', line 26

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

#maxitest_wait_for_extra_threadsObject

also a helper methods for users



21
22
23
# File 'lib/maxitest/threads.rb', line 21

def maxitest_wait_for_extra_threads
  sleep 0.01 while maxitest_extra_threads.any?
end

#setupObject



7
8
9
10
# File 'lib/maxitest/threads.rb', line 7

def setup
  @maxitest_threads_before = Thread.list
  super
end

#teardownObject



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

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