Skip to content

Commit a086ffe

Browse files
committed
fix(matrix): ensure unrelated dependencies are not included in a matrix result when three pacticipants each have dependencies on each other
1 parent cba120e commit a086ffe

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/pact_broker/matrix/row.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def where_consumer_and_provider_in selectors
5353
),
5454
Sequel.|(
5555
*QueryHelper.provider_and_maybe_provider_version_match_any_selector_or_verification_is_missing(selectors)
56-
)
56+
),
57+
QueryHelper.either_consumer_or_provider_was_specified_in_query(selectors)
5758
)
5859
}
5960
end
@@ -94,6 +95,18 @@ def self.provider_and_maybe_provider_version_match_any_selector_or_verification_
9495
provider_verification_is_missing_for_matching_selector(s)
9596
}
9697
end
98+
99+
# Some selecters are specified in the query, others are implied (when only one pacticipant is specified,
100+
# the integrations are automatically worked out, and the selectors for these are of type :implied )
101+
# When there are 3 pacticipants that each have dependencies on each other (A->B, A->C, B->C), the query
102+
# to deploy C (implied A, implied B, specified C) was returning the A->B row because it matched the
103+
# implied selectors as well.
104+
# This extra filter makes sure that every row that is returned actually matches one of the specified
105+
# selectors.
106+
def self.either_consumer_or_provider_was_specified_in_query(selectors)
107+
specified_pacticipant_ids = selectors.select{ |s| s[:type] == :specified }.collect{ |s| s[:pacticipant_id] }
108+
Sequel.|({ consumer_id: specified_pacticipant_ids } , { provider_id: specified_pacticipant_ids })
109+
end
97110
end
98111

99112
def where_consumer_or_provider_is s

spec/lib/pact_broker/matrix/repository_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,30 @@ def shorten_rows rows
10351035
expect(subject.rows.first.consumer_version_number).to eq "2"
10361036
end
10371037
end
1038+
1039+
describe "deploying a provider when there is a three way dependency between 3 pacticipants" do
1040+
before do
1041+
# A->B, A->C, B->C, deploying C
1042+
td.create_pact_with_hierarchy("B", "1", "C")
1043+
.create_verification(provider_version: "10")
1044+
.create_consumer("A")
1045+
.create_consumer_version("2")
1046+
.create_pact
1047+
.create_verification(provider_version: "10")
1048+
.use_provider("B")
1049+
.create_pact
1050+
end
1051+
1052+
let(:selectors) { [ { pacticipant_name: "C", pacticipant_version_number: "10" } ] }
1053+
let(:options) { { latestby: "cvp", limit: "100", latest: true} }
1054+
let(:rows) { Repository.new.find(selectors, options) }
1055+
1056+
subject { shorten_rows(rows) }
1057+
1058+
it "only includes rows that involve the specified pacticipant" do
1059+
expect(subject.all?{ | row | row.include?("C") } ).to be true
1060+
end
1061+
end
10381062
end
10391063
end
10401064
end

0 commit comments

Comments
 (0)