mirror of
https://github.com/discourse/discourse.git
synced 2025-02-21 10:13:43 +08:00
add more diagnostics for flaky spec
This commit is contained in:
parent
1d90f6016a
commit
c7532003f3
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user