Skip to content

A platform for community discussion. Free, open, simple.

DEV: Silence expected error/debug output in system specs (#39164)

Jarek Radosze559da5bf705
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index d9900f553bf..edf2f5db65f 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -52,7 +52,7 @@ jobs:
PGPASSWORD: discourse
USES_PARALLEL_DATABASES: ${{ matrix.build_type == 'backend' || matrix.build_type == 'system' }}
CAPYBARA_DEFAULT_MAX_WAIT_TIME: 20
- MINIO_RUNNER_LOG_LEVEL: DEBUG
+ MINIO_RUNNER_LOG_LEVEL: WARN
DISCOURSE_TURBO_RSPEC_RETRY_AND_LOG_FLAKY_TESTS: ${{ (matrix.build_type == 'system' || matrix.build_type == 'backend') && '1' }}
CHEAP_SOURCE_MAPS: "1"
MINIO_RUNNER_INSTALL_DIR: /home/discourse/.minio_runner
diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb
index a4ca7f4f733..0c1a9f54dd6 100644
--- a/app/controllers/uploads_controller.rb
+++ b/app/controllers/uploads_controller.rb
@@ -386,7 +386,7 @@ class UploadsController < ApplicationController
response.headers["Content-Security-Policy"] = "sandbox;"
file_path = Discourse.store.path_for(upload)
- return render_404 unless file_path
+ return render_404 unless file_path && File.exist?(file_path)
send_file(file_path, opts)
end
diff --git a/config/environments/test.rb b/config/environments/test.rb
index fa04be355d7..d0f8d59d7ef 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -77,6 +77,10 @@ Discourse::Application.configure do
config.logger = Logger.new(STDOUT)
config.log_level =
ENV["RAILS_TEST_LOG_LEVEL"].present? ? ENV["RAILS_TEST_LOG_LEVEL"].to_sym : :info
+
+ # Don't log rescued exceptions (RoutingError, RecordNotFound, etc.)
+ # These are expected in system specs that intentionally visit nonexistent routes
+ config.action_dispatch.log_rescued_responses = false
else
config.logger = Logger.new(nil)
config.log_level = :fatal
diff --git a/lib/hijack.rb b/lib/hijack.rb
index d21e6f04465..76ed6a61425 100644
--- a/lib/hijack.rb
+++ b/lib/hijack.rb
@@ -106,7 +106,7 @@ module Hijack
io.write "\r\n"
io.write body
- rescue Errno::EPIPE, IOError
+ rescue Errno::EPIPE, Errno::ECONNRESET, IOError
# happens if client terminated before we responded, ignore
io = nil
ensure
diff --git a/plugins/chat/spec/system/chat_composer_draft_spec.rb b/plugins/chat/spec/system/chat_composer_draft_spec.rb
index 36b033f7c17..8d7df18df8b 100644
--- a/plugins/chat/spec/system/chat_composer_draft_spec.rb
+++ b/plugins/chat/spec/system/chat_composer_draft_spec.rb
@@ -86,16 +86,7 @@ RSpec.describe "Chat composer draft" do
end
context "with uploads" do
- fab!(:upload_1) do
- Fabricate(
- :upload,
- url: "/images/logo-dark.png",
- original_filename: "logo_dark.png",
- width: 400,
- height: 300,
- extension: "png",
- )
- end
+ fab!(:upload_1, :image_upload)
before do
create_draft(channel_1, user: current_user, data: { message: "draft", uploads: [upload_1] })
@@ -215,16 +206,7 @@ RSpec.describe "Chat composer draft" do
end
context "with uploads" do
- fab!(:upload_1) do
- Fabricate(
- :upload,
- url: "/images/logo-dark.png",
- original_filename: "logo_dark.png",
- width: 400,
- height: 300,
- extension: "png",
- )
- end
+ fab!(:upload_1, :image_upload)
before do
create_draft(
diff --git a/plugins/chat/spec/system/deleted_channel_spec.rb b/plugins/chat/spec/system/deleted_channel_spec.rb
index 0431f925e68..f8ea6634f12 100644
--- a/plugins/chat/spec/system/deleted_channel_spec.rb
+++ b/plugins/chat/spec/system/deleted_channel_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe "Deleted channel" do
context "when visiting deleted channel" do
it "redirects to homepage" do
- chat_page.visit_channel(channel_1)
+ chat_page.visit_channel(channel_1, check: false)
expect(page).to have_content("Not Found") # this is not a translated key
end
diff --git a/plugins/chat/spec/system/sidebar_navigation_menu_spec.rb b/plugins/chat/spec/system/sidebar_navigation_menu_spec.rb
index 02e8b78c1b6..fc60b925780 100644
--- a/plugins/chat/spec/system/sidebar_navigation_menu_spec.rb
+++ b/plugins/chat/spec/system/sidebar_navigation_menu_spec.rb
@@ -191,6 +191,9 @@ RSpec.describe "Sidebar navigation menu" do
before do
other_user.username = "<script>alert('hello')</script>"
+ # Use an uploaded avatar to avoid a letter_avatar request with the
+ # malicious username (which contains `/` and breaks URL routing)
+ other_user.uploaded_avatar_id = Fabricate(:image_upload).id
other_user.save!(validate: false)
end
diff --git a/spec/system/impersonation_spec.rb b/spec/system/impersonation_spec.rb
index c0f98be5485..5ff95f36871 100644
--- a/spec/system/impersonation_spec.rb
+++ b/spec/system/impersonation_spec.rb
@@ -58,9 +58,12 @@ describe "Impersonation" do
visit("/admin/users/#{user.id}/#{user.username}")
- page.find(".btn-impersonate").click
+ # Suppress the expected error from the intentionally raised StandardError
+ silence_stdout do
+ page.find(".btn-impersonate").click
- expect(dialog).to be_open
- expect(dialog).to have_content(I18n.t("admin_js.admin.impersonate.error"))
+ expect(dialog).to be_open
+ expect(dialog).to have_content(I18n.t("admin_js.admin.impersonate.error"))
+ end
end
end
diff --git a/spec/system/locale_spec.rb b/spec/system/locale_spec.rb
index be2c68a7263..23bb3cd5145 100644
--- a/spec/system/locale_spec.rb
+++ b/spec/system/locale_spec.rb
@@ -197,7 +197,10 @@ RSpec.describe "Locale choice" do
it "does not throw error for malformed messages" do
SiteSetting.default_locale = "zh_TW"
- visit "/"
+
+ # Suppress the expected error from the intentionally malformed zh_TW MF string
+ silence_stdout { visit "/" }
+
expect(page).to have_css("#site-logo")
expect(page.evaluate_script("Object.keys(I18n._mfMessages._data)").length).to eq(0)
diff --git a/spec/system/network_disconnected_spec.rb b/spec/system/network_disconnected_spec.rb
index 841e5ef4e13..e6d9e200edb 100644
--- a/spec/system/network_disconnected_spec.rb
+++ b/spec/system/network_disconnected_spec.rb
@@ -4,10 +4,9 @@ RSpec.describe "Network Disconnected" do
let(:cdp) { PageObjects::CDP.new }
it "NetworkConnectivity service adds class to DOM and displays offline indicator" do
- skip_on_ci!(<<~TEXT)
- In CI this test will randomly flake - timing issue with the offline indicator
- not being rendered soon enough after network conditions change
- TEXT
+ skip_on_ci!(
+ "In CI this test will randomly flake - timing issue with the offline indicator not being rendered soon enough after network conditions change",
+ )
SiteSetting.enable_offline_indicator = true
diff --git a/spec/system/welcome_banner_spec.rb b/spec/system/welcome_banner_spec.rb
index 4699dc0cddb..b3911bcfb71 100644
--- a/spec/system/welcome_banner_spec.rb
+++ b/spec/system/welcome_banner_spec.rb
@@ -273,7 +273,7 @@ describe "Welcome banner" do
visit "/filter?q=tag%3Ain-progress"
expect(banner).to be_visible
- visit "/upcoming-events?view=month"
+ visit "/about"
expect(banner).to be_hidden
end
@@ -288,7 +288,7 @@ describe "Welcome banner" do
expect(banner).to be_visible
end
- visit "/my/posts"
+ visit "/about"
expect(banner).to be_hidden
end