lib/pact/mock_service/session.rb in pact-mock_service-3.2.1 vs lib/pact/mock_service/session.rb in pact-mock_service-3.3.0

- old
+ new

@@ -15,10 +15,12 @@ @pact_written = false @logger = options[:logger] @expected_interactions = Interactions::ExpectedInteractions.new @actual_interactions = Interactions::ActualInteractions.new @verified_interactions = Interactions::VerifiedInteractions.new + @warn_on_too_many_interactions = options[:warn_on_too_many_interactions] || false + @max_concurrent_interactions_before_warning = get_max_concurrent_interactions_before_warning @consumer_contract_details = { pact_dir: options[:pact_dir], consumer: {name: options[:consumer]}, provider: {name: options[:provider]}, interactions: verified_interactions, @@ -62,14 +64,19 @@ end end private + attr_reader :warn_on_too_many_interactions, :max_concurrent_interactions_before_warning + def really_add_expected_interaction interaction expected_interactions << interaction logger.info "Registered expected interaction #{interaction.request.method_and_path}" logger.debug JSON.pretty_generate InteractionDecorator.new(interaction) + if warn_on_too_many_interactions && expected_interactions.size > max_concurrent_interactions_before_warning + logger.warn "You currently have #{expected_interactions.size} interactions mocked at the same time. This suggests the scope of your consumer tests is larger than recommended, and you may find them hard to debug and maintain. See https://pact.io/too-many-interactions for more information." + end end def handle_almost_duplicate_interaction previous_interaction, interaction message = Interactions::InteractionDiffMessage.new(previous_interaction, interaction).to_s logger.error message @@ -79,8 +86,11 @@ def interaction_already_verified_with_same_description_and_provider_state_but_not_equal interaction other = verified_interactions.find_matching_description_and_provider_state interaction other && other != interaction ? other : nil end + def get_max_concurrent_interactions_before_warning + ENV['PACT_MAX_CONCURRENT_INTERACTIONS_BEFORE_WARNING'] ? ENV['PACT_MAX_CONCURRENT_INTERACTIONS_BEFORE_WARNING'].to_i : 3 + end end end end