From 80f1be6ffadac59c5a6ce0b63c603155195670cd Mon Sep 17 00:00:00 2001 From: fsainz Date: Tue, 26 Jul 2022 14:17:15 +0200 Subject: [PATCH] fixes memoized benchmark error --- lib/worker_tools/benchmark.rb | 6 ++++-- test/worker_tools/benchmark_test.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/worker_tools/benchmark.rb b/lib/worker_tools/benchmark.rb index 12a667c..98f0f1a 100644 --- a/lib/worker_tools/benchmark.rb +++ b/lib/worker_tools/benchmark.rb @@ -6,14 +6,16 @@ module Benchmark attr_accessor :benchmark def with_wrapper_benchmark(&block) + benchmark_error = nil + benchmark = ::Benchmark.measure do block.call rescue StandardError => e - @benchmark_error = e + benchmark_error = e end model.meta['duration'] = benchmark.real.round if model.respond_to?(:meta) - raise @benchmark_error if @benchmark_error + raise benchmark_error if benchmark_error end end end diff --git a/test/worker_tools/benchmark_test.rb b/test/worker_tools/benchmark_test.rb index 66f2088..6d8570d 100644 --- a/test/worker_tools/benchmark_test.rb +++ b/test/worker_tools/benchmark_test.rb @@ -44,6 +44,14 @@ def @importer.run assert_raises(StandardError) { @importer.perform(@import) } expect(@importer.model.meta['duration'] >= 1).must_equal true + + # it does not raise on a second perform + + def @importer.run + true + end + + @importer.perform(@import) end end end