Only mock Addrinfo.getaddrinfo once in the stub_requests helper
Context
See this discussion.
Calling stub_dns
from the stub_requests.rb
file, it mocks Addrinfo.getaddrinfo
for all calls, not just one call as one would expect:
def stub_dns(url, ip_address:, port: 80)
allow(Addrinfo).to receive(:getaddrinfo)
.with(url.hostname, url.port, nil, :STREAM)
.and_return([addr])
[...]
end
Goals
- Stub
Addrinfo.getaddrinfo
only once:
def stub_dns(url, ip_address:, port: 80)
allow(Addrinfo).to receive(:getaddrinfo)
.with(url.hostname, url.port, nil, :STREAM)
.and_return([addr])
.once
[...]
end
- As discussed in !139417 (comment 1692227967), there are some specs that are failing because of this. They will need to be fixed as well
- Optionally, please discuss creating a Rubocop cop to ensure those problems are prevented in the future.
- We have two
stub_requests.rb files that have an almost identical content:
spec/support/helpers/stub_requests.rband
gems/gitlab-http/spec/gitlab/stub_requests.rb`. Consider creating an issue to use only one of those two to reduce code duplication.
Specs failing
spec/tasks/gitlab/usage_data_rake_spec.rb
spec/services/web_hook_service_spec.rb
spec/services/service_ping/submit_service_ping_service_spec.rb
spec/services/projects/lfs_pointers/lfs_download_service_spec.rb
spec/requests/recursive_webhook_detection_spec.rb
spec/requests/api/projects_spec.rb
spec/models/integrations/pivotaltracker_spec.rb
spec/models/integrations/campfire_spec.rb
spec/lib/mattermost/session_spec.rb
spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb
spec/lib/gitlab/ci/config/external/mapper/verifier_spec.rb
spec/lib/atlassian/jira_connect/client_spec.rb
ee/spec/requests/api/projects_spec.rb
ee/spec/features/subscriptions/subscription_flow_for_existing_user_with_eligible_group_spec.rb
ee/spec/features/groups/user_interacts_with_unlimited_members_during_trial_alert_spec.rb
ee/spec/features/groups/usage_quotas/seats_tab_spec.rb
ee/spec/features/groups/members/manage_members_spec.rb
ee/spec/features/groups/members/manage_groups_spec.rb
ee/spec/features/groups/billing_spec.rb
ee/spec/features/billings/qrtly_reconciliation_alert_spec.rb
ee/spec/features/billings/billing_plans_spec.rb
Edited by David Dieulivol