Skip to content

Commit

Permalink
fixes memoized benchmark error
Browse files Browse the repository at this point in the history
  • Loading branch information
fsainz committed Jul 26, 2022
1 parent 76a2e3d commit 80f1be6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/worker_tools/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/worker_tools/benchmark_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 80f1be6

Please sign in to comment.