mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:41:17 +08:00
add more diagnostics for flaky spec
This commit is contained in:
@ -61,6 +61,7 @@ describe Scheduler::Manager do
|
|||||||
before do
|
before do
|
||||||
expect(ActiveRecord::Base.connection_pool.connections.length).to eq(1)
|
expect(ActiveRecord::Base.connection_pool.connections.length).to eq(1)
|
||||||
@thread_count = Thread.list.count
|
@thread_count = Thread.list.count
|
||||||
|
@thread_ids = Thread.list.map { |t| t.object_id }
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
@ -77,7 +78,29 @@ describe Scheduler::Manager do
|
|||||||
ActiveRecord::Base.connection_pool.remove(c)
|
ActiveRecord::Base.connection_pool.remove(c)
|
||||||
end
|
end
|
||||||
expect(ActiveRecord::Base.connection_pool.connections.length).to eq(1)
|
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
|
@thread_count == Thread.list.count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -61,7 +61,7 @@ module Helpers
|
|||||||
Guardian.stubs(new: guardian).with(user)
|
Guardian.stubs(new: guardian).with(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def wait_for(&blk)
|
def wait_for(on_fail: nil, &blk)
|
||||||
i = 0
|
i = 0
|
||||||
result = false
|
result = false
|
||||||
while !result && i < 1000
|
while !result && i < 1000
|
||||||
@ -70,6 +70,7 @@ module Helpers
|
|||||||
sleep 0.001
|
sleep 0.001
|
||||||
end
|
end
|
||||||
|
|
||||||
|
on_fail&.call
|
||||||
expect(result).to eq(true)
|
expect(result).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user