Fix flaky web push test and deduplicate DNS stub helper (#2825)
* Extract shared DnsTestHelper from duplicated stub_dns_resolution methods * Fix flaky WebTest by stubbing DNS resolution for push subscription creation
This commit is contained in:
@@ -247,11 +247,4 @@ class FlatJsonParamsTest < ActionDispatch::IntegrationTest
|
||||
assert_response :no_content
|
||||
assert_equal "Flat Join", users(:david).reload.name
|
||||
end
|
||||
|
||||
private
|
||||
def stub_dns_resolution(*ips)
|
||||
dns_mock = mock("dns")
|
||||
dns_mock.stubs(:each_address).multiple_yields(*ips)
|
||||
Resolv::DNS.stubs(:open).yields(dns_mock)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -92,11 +92,4 @@ class Users::PushSubscriptionsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
private
|
||||
def stub_dns_resolution(*ips)
|
||||
dns_mock = mock("dns")
|
||||
dns_mock.stubs(:each_address).multiple_yields(*ips)
|
||||
Resolv::DNS.stubs(:open).yields(dns_mock)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,6 +5,8 @@ class Notification::PushTarget::WebTest < ActiveSupport::TestCase
|
||||
@user = users(:david)
|
||||
@notification = notifications(:logo_mentioned_david)
|
||||
|
||||
stub_dns_resolution("142.250.185.206")
|
||||
|
||||
@user.push_subscriptions.create!(
|
||||
endpoint: "https://fcm.googleapis.com/fcm/send/test123",
|
||||
p256dh_key: "test_key",
|
||||
|
||||
@@ -115,11 +115,4 @@ class Push::SubscriptionTest < ActiveSupport::TestCase
|
||||
assert subscription.valid?, "Expected #{endpoint} to be valid, got errors: #{subscription.errors.full_messages}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def stub_dns_resolution(*ips)
|
||||
dns_mock = mock("dns")
|
||||
dns_mock.stubs(:each_address).multiple_yields(*ips)
|
||||
Resolv::DNS.stubs(:open).yields(dns_mock)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -82,11 +82,4 @@ class SsrfProtectionTest < ActiveSupport::TestCase
|
||||
stub_dns_resolution("::93.184.216.34")
|
||||
assert_nil SsrfProtection.resolve_public_ip("compat-public.example.com")
|
||||
end
|
||||
|
||||
private
|
||||
def stub_dns_resolution(*ips)
|
||||
dns_mock = mock("dns")
|
||||
dns_mock.stubs(:each_address).multiple_yields(*ips)
|
||||
Resolv::DNS.stubs(:open).yields(dns_mock)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -473,11 +473,4 @@ class Webhook::DeliveryTest < ActiveSupport::TestCase
|
||||
assert_equal 200, delivery.response[:code]
|
||||
assert delivery.succeeded?
|
||||
end
|
||||
|
||||
private
|
||||
def stub_dns_resolution(*ips)
|
||||
dns_mock = mock("dns")
|
||||
dns_mock.stubs(:each_address).multiple_yields(*ips)
|
||||
Resolv::DNS.stubs(:open).yields(dns_mock)
|
||||
end
|
||||
end
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ module ActiveSupport
|
||||
fixtures :all
|
||||
|
||||
include ActiveJob::TestHelper
|
||||
include ActionTextTestHelper, CachingTestHelper, CardTestHelper, ChangeTestHelper, SessionTestHelper
|
||||
include ActionTextTestHelper, CachingTestHelper, CardTestHelper, ChangeTestHelper, DnsTestHelper, SessionTestHelper
|
||||
include Turbo::Broadcastable::TestHelper
|
||||
|
||||
# Jobs must carry their own account context via AccountTenanted,
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
module DnsTestHelper
|
||||
private
|
||||
|
||||
def stub_dns_resolution(*ips)
|
||||
dns_mock = mock("dns")
|
||||
dns_mock.stubs(:each_address).multiple_yields(*ips)
|
||||
Resolv::DNS.stubs(:open).yields(dns_mock)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user