add more diagnostics for flaky spec

This commit is contained in:
Sam 2017-08-23 10:41:47 -04:00
parent 1d90f6016a
commit c7532003f3
2 changed files with 26 additions and 2 deletions

View File

@ -61,6 +61,7 @@ describe Scheduler::Manager do
before do
expect(ActiveRecord::Base.connection_pool.connections.length).to eq(1)
@thread_count = Thread.list.count
@thread_ids = Thread.list.map { |t| t.object_id }
end
after do
@ -77,7 +78,29 @@ describe Scheduler::Manager do
ActiveRecord::Base.connection_pool.remove(c)
end
expect(ActiveRecord::Base.connection_pool.connections.length).to eq(1)
wait_for do
on_thread_mismatch = lambda do
current = Thread.list.map { |t| t.object_id }
extra = current - @thread_ids
missing = @thread_ids - current
if missing.length > 0
STDERR.puts "\nMissing Threads #{missing.length} thread/s"
end
if extra.length > 0
Thread.list.each do |thread|
if extra.include?(thread.object_id)
STDERR.puts "\nExtra Thread Backtrace:"
STDERR.puts thread.backtrace
STDERR.puts
end
end
end
end
wait_for(on_fail: on_thread_mismatch) do
@thread_count == Thread.list.count
end
end

View File

@ -61,7 +61,7 @@ module Helpers
Guardian.stubs(new: guardian).with(user)
end
def wait_for(&blk)
def wait_for(on_fail: nil, &blk)
i = 0
result = false
while !result && i < 1000
@ -70,6 +70,7 @@ module Helpers
sleep 0.001
end
on_fail&.call
expect(result).to eq(true)
end