From 20cda5d6892f620d123c6586d562c5950d4f53ba Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 8 Apr 2019 15:57:47 +0100 Subject: [PATCH] DEV: Raise exceptions when jobs fail in test mode Previously jobs would fail silently in test mode. Now they will raise the exception and cause the relevant test to fail. This identified a few broken tests, which I will fix in a followup commit --- lib/discourse.rb | 2 ++ spec/components/discourse_spec.rb | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/discourse.rb b/lib/discourse.rb index 736dfcaeca2..4ef1ebb15e0 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -54,6 +54,8 @@ module Discourse current_db: cm.current_db, current_hostname: cm.current_hostname }.merge(context)) + + raise ex if Rails.env.test? end # Expected less matches than what we got in a find diff --git a/spec/components/discourse_spec.rb b/spec/components/discourse_spec.rb index 058b61b7b1e..a272269f069 100644 --- a/spec/components/discourse_spec.rb +++ b/spec/components/discourse_spec.rb @@ -274,7 +274,10 @@ describe Discourse do it "should not fail when called" do exception = StandardError.new - Discourse.handle_job_exception(exception, nil, nil) + expect do + Discourse.handle_job_exception(exception, nil, nil) + end.to raise_error(StandardError) # Raises in test mode, catch it + expect(logger.exception).to eq(exception) expect(logger.context.keys).to eq([:current_db, :current_hostname]) end @@ -282,7 +285,10 @@ describe Discourse do it "correctly passes extra context" do exception = StandardError.new - Discourse.handle_job_exception(exception, { message: "Doing a test", post_id: 31 }, nil) + expect do + Discourse.handle_job_exception(exception, { message: "Doing a test", post_id: 31 }, nil) + end.to raise_error(StandardError) # Raises in test mode, catch it + expect(logger.exception).to eq(exception) expect(logger.context.keys.sort).to eq([:current_db, :current_hostname, :message, :post_id].sort) end