Skip to content

Commit

Permalink
fix(matrix): ensure unrelated dependencies are not included in a matr…
Browse files Browse the repository at this point in the history
…ix result when three pacticipants each have dependencies on each other
  • Loading branch information
bethesque committed Jun 4, 2019
1 parent cba120e commit a086ffe
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/pact_broker/matrix/row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def where_consumer_and_provider_in selectors
),
Sequel.|(
*QueryHelper.provider_and_maybe_provider_version_match_any_selector_or_verification_is_missing(selectors)
)
),
QueryHelper.either_consumer_or_provider_was_specified_in_query(selectors)
)
}
end
Expand Down Expand Up @@ -94,6 +95,18 @@ def self.provider_and_maybe_provider_version_match_any_selector_or_verification_
provider_verification_is_missing_for_matching_selector(s)
}
end

# Some selecters are specified in the query, others are implied (when only one pacticipant is specified,
# the integrations are automatically worked out, and the selectors for these are of type :implied )
# When there are 3 pacticipants that each have dependencies on each other (A->B, A->C, B->C), the query
# to deploy C (implied A, implied B, specified C) was returning the A->B row because it matched the
# implied selectors as well.
# This extra filter makes sure that every row that is returned actually matches one of the specified
# selectors.
def self.either_consumer_or_provider_was_specified_in_query(selectors)
specified_pacticipant_ids = selectors.select{ |s| s[:type] == :specified }.collect{ |s| s[:pacticipant_id] }
Sequel.|({ consumer_id: specified_pacticipant_ids } , { provider_id: specified_pacticipant_ids })
end
end

def where_consumer_or_provider_is s
Expand Down
24 changes: 24 additions & 0 deletions spec/lib/pact_broker/matrix/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,30 @@ def shorten_rows rows
expect(subject.rows.first.consumer_version_number).to eq "2"
end
end

describe "deploying a provider when there is a three way dependency between 3 pacticipants" do
before do
# A->B, A->C, B->C, deploying C
td.create_pact_with_hierarchy("B", "1", "C")
.create_verification(provider_version: "10")
.create_consumer("A")
.create_consumer_version("2")
.create_pact
.create_verification(provider_version: "10")
.use_provider("B")
.create_pact
end

let(:selectors) { [ { pacticipant_name: "C", pacticipant_version_number: "10" } ] }
let(:options) { { latestby: "cvp", limit: "100", latest: true} }
let(:rows) { Repository.new.find(selectors, options) }

subject { shorten_rows(rows) }

it "only includes rows that involve the specified pacticipant" do
expect(subject.all?{ | row | row.include?("C") } ).to be true
end
end
end
end
end

0 comments on commit a086ffe

Please sign in to comment.