OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add spec helper function to emulate timeout when VCR is being used.
Pavel Balashoufa3a47ff0379
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/set_permissions_command_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/set_permissions_command_spec.rbindex 22e00890bc3..646fa5ebf27 100644--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/set_permissions_command_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/set_permissions_command_spec.rb@@ -143,17 +143,14 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::SetPermissiocontext "when there is a timeout" doit "logs a warnig and does not raise NoMethodError", vcr: "one_drive/set_permissions_delete_permission_read" do+ stub_request_with_timeout(:post, /invite$/)allow(OpenProject.logger).to receive(:warn)- request_mock = HTTPX::Request.new("POST", "http://example.com/")- error_response_mock = HTTPX::ErrorResponse.new(request_mock, HTTPX::ConnectTimeoutError.new(60, "timed out while waiting on select"), {})- allow_any_instance_of(HTTPX::Session).to receive(:post).with(any_args).and_call_original- allow_any_instance_of(HTTPX::Session).to receive(:post).with(/\/invite$/, anything).and_return(error_response_mock)permissions_command.call(path:, permissions: { read: ["d6e00f6d-1ae7-43e6-b0af-15d99a56d4ce"] })expect(OpenProject.logger).to have_received(:warn)- .with(command: Storages::Peripherals::StorageInteraction::OneDrive::SetPermissionsCommand,+ .with(command: described_class,message: nil,data: { body: "/usr/local/bundle/gems/httpx-1.2.3/lib/httpx/response.rb:260:in `full_message': timed out while waiting on select (HTTPX::ConnectTimeoutError)\n",status: nil }).oncediff --git a/modules/storages/spec/services/storages/one_drive_managed_folder_sync_service_spec.rb b/modules/storages/spec/services/storages/one_drive_managed_folder_sync_service_spec.rbindex c0cc466bfc8..760dae4b2ff 100644--- a/modules/storages/spec/services/storages/one_drive_managed_folder_sync_service_spec.rb+++ b/modules/storages/spec/services/storages/one_drive_managed_folder_sync_service_spec.rb@@ -242,6 +242,7 @@ RSpec.describe Storages::OneDriveManagedFolderSyncService, :webmock docontext "when reading the root folder fails" dobefore { storage.update(drive_id: "THIS-IS-NOT-A-DRIVE-ID") }+it "returns a failure in case retrieving the root list fails", vcr: "one_drive/sync_service_root_read_failure" doexpect(service.call).to be_failureend@@ -257,10 +258,7 @@ RSpec.describe Storages::OneDriveManagedFolderSyncService, :webmock doendit "does not break in case of timeout", vcr: "one_drive/sync_service_root_read_failure" do- request_mock = HTTPX::Request.new("POST", "http://example.com/")- error_response_mock = HTTPX::ErrorResponse.new(request_mock, HTTPX::ConnectTimeoutError.new(60, "timed out while waiting on select"), {})- allow_any_instance_of(HTTPX::Session).to receive(:get).with(any_args).and_call_original- allow_any_instance_of(HTTPX::Session).to receive(:get).with(/\/root\/children$/).and_return(error_response_mock)+ stub_request_with_timeout(:get, /\/root\/children$/)expect(service.call).to be_failurediff --git a/spec/support/vcr.rb b/spec/support/vcr.rbindex b4e22e39c59..17861036dd4 100644--- a/spec/support/vcr.rb+++ b/spec/support/vcr.rb@@ -30,6 +30,16 @@require "vcr"+module VCRTimeoutHelper+ def stub_request_with_timeout(method, path_matcher)+ request_mock = HTTPX::Request.new(method.to_s.upcase, "https://example.com")+ error_response_mock = HTTPX::ErrorResponse.new(request_mock,+ HTTPX::ConnectTimeoutError.new(60, "timed out while waiting on select"), {})+ allow_any_instance_of(HTTPX::Session).to receive(method.to_sym).with(any_args).and_call_original+ allow_any_instance_of(HTTPX::Session).to receive(method.to_sym).with(path_matcher, any_args).and_return(error_response_mock)+ end+end+VCR.configure do |config|config.cassette_library_dir = "spec/support/fixtures/vcr_cassettes"config.hook_into :webmock@@ -64,6 +74,7 @@ endVCR.turn_off!RSpec.configure do |config|+ config.include(VCRTimeoutHelper)config.around(:example, :vcr) do |example|# Only enable VCR's webmock integration for tests tagged with :vcr otherwise interferes with WebMock# See: https://github.com/vcr/vcr/issues/146