mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 05:04:22 +08:00
4ea21fa2d0
This change both speeds up specs (less strings to allocate) and helps catch cases where methods in Discourse are mutating inputs. Overall we will be migrating everything to use #frozen_string_literal: true it will take a while, but this is the first and safest move in this direction
44 lines
888 B
Ruby
44 lines
888 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
require_dependency 'method_profiler'
|
|
|
|
describe MethodProfiler do
|
|
class Sneetch
|
|
def beach
|
|
end
|
|
|
|
def recurse(count = 5)
|
|
if count > 0
|
|
recurse(count - 1)
|
|
end
|
|
end
|
|
end
|
|
|
|
it "can bypass recursion on demand" do
|
|
MethodProfiler.patch(Sneetch, [:recurse], :recurse, no_recurse: true)
|
|
|
|
MethodProfiler.start
|
|
Sneetch.new.recurse
|
|
result = MethodProfiler.stop
|
|
|
|
expect(result[:recurse][:calls]).to eq(1)
|
|
end
|
|
|
|
it "can transfer data between threads" do
|
|
MethodProfiler.patch(Sneetch, [:beach], :at_beach)
|
|
|
|
MethodProfiler.start
|
|
Sneetch.new.beach
|
|
data = MethodProfiler.transfer
|
|
result = nil
|
|
Thread.new do
|
|
MethodProfiler.start(data)
|
|
Sneetch.new.beach
|
|
result = MethodProfiler.stop
|
|
end.join
|
|
|
|
expect(result[:at_beach][:calls]).to eq(2)
|
|
end
|
|
end
|