Skip to content

Commit f435f38

Browse files
committed
Discard block result during backend fallback
AppProfiler.run normally returns the profile result, so we should be consistent.
1 parent ef4da04 commit f435f38

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/app_profiler.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def run(*args, backend: nil, **kwargs, &block)
100100
)
101101
end
102102
yield
103+
nil # no profile result
103104
ensure
104105
self.backend = original_backend if backend
105106
ProfileId::Current.reset

test/app_profiler/run_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ class RunTest < TestCase
3535
assert_operator profile.duration, :>=, 0.1
3636
end
3737

38+
test ".run runs the block but does not return its result when the backend raises" do
39+
ran = false
40+
result = AppProfiler.run(backend: "not a real backend") do
41+
ran = true
42+
:block_value
43+
end
44+
45+
assert(ran)
46+
assert_nil(result)
47+
end
48+
3849
test ".run sets the backend then returns to the previous value" do
3950
orig_backend = AppProfiler.backend
4051
skip("Vernier not supported") unless AppProfiler.vernier_supported?

0 commit comments

Comments
 (0)