karafka-testing 2.3.2 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4932859009198b689571ee03c117e5255efbba52deb34874c689577cd456bf47
4
- data.tar.gz: a83d1892a15392beb4889d77f642c2368b9a57a07073e9ce6ae4f884ad6ba61c
3
+ metadata.gz: 91a12f6c61514bc890bdfd8f6c91e1a834dd1516299f8a6d421c54037d3b55b3
4
+ data.tar.gz: 70d467cb5994992d5a3046511bca0676fabc673b2b36c45d366b98d6aeeeae06
5
5
  SHA512:
6
- metadata.gz: 0c99a0ece8c0ae1e2b46541148236b86ce26f1652c6e3cd82e4d3158ed42797b67019a4ec79db3c21efbc9a8e65e53e7e07cc6effa876190b5377dbd1cf2a8f2
7
- data.tar.gz: d422ab991a2cfa2796e8dff02d9902c19f3d64e8f6d4d269283468abfbb0c20569f699faeef4f78dac440662ab94fea7da293361a7f824ba5219070358e6c1fa
6
+ metadata.gz: ebb18327ff48e4443377a54a09d35611c84f6806bc298ceb0792d1b2862f7f1c35e2c528bdb8b7e611d61998201f851dc8648530d398fdbbd33ec504d7fedae7
7
+ data.tar.gz: 9898b5f1bd9264b696361cfd60039226864eb26743722c21a251fad26d2bd9d633b9be0cadcf62dbc7638a5287b69a0aaf720b12ad70595cc03c6bc1c4fe920f
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Karafka Test gem changelog
2
2
 
3
+ ## 2.3.3 (2024-04-19)
4
+ - [Refactor] Extract common components for Minitest and RSpec.
5
+ - [Fix] Fix a case where multiplexed SG would fail with `TopicInManyConsumerGroupsError`
6
+
3
7
  ## 2.3.2 (2024-04-03)
4
8
  - [Enhancement] Support `Minitest::Spec`.
5
9
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-testing (2.3.2)
4
+ karafka-testing (2.3.3)
5
5
  karafka (>= 2.3.0, < 2.4.0)
6
6
  waterdrop (>= 2.6.12)
7
7
 
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ module Testing
5
+ # Common helper methods that are shared in between RSpec and Minitest
6
+ module Helpers
7
+ class << self
8
+ # Finds all the routing topics matching requested topic within all topics or within
9
+ # provided consumer group based on name
10
+ #
11
+ # @param requested_topic [String] requested topic name
12
+ # @param requested_consumer_group [String] requested consumer group or nil to look in all
13
+ # @return [Array<Karafka::Routing::Topic>] all matching topics
14
+ #
15
+ # @note Since we run the lookup on subscription groups, the search will automatically
16
+ # expand with matching patterns
17
+ def karafka_consumer_find_candidate_topics(requested_topic, requested_consumer_group)
18
+ karafka_consumer_find_subscription_groups(requested_consumer_group)
19
+ # multiplexed subscriptions of the same origin share name, thus we can reduced
20
+ # multiplexing to the first one as during testing, there is no multiplexing parallel
21
+ # execution anyhow
22
+ .uniq(&:name)
23
+ .map(&:topics)
24
+ .filter_map do |topics|
25
+ topics.find(requested_topic.to_s)
26
+ rescue Karafka::Errors::TopicNotFoundError
27
+ nil
28
+ end
29
+ end
30
+
31
+ # Finds subscription groups from the requested consumer group or selects all if no
32
+ # consumer group specified
33
+ # @param requested_consumer_group [String] requested consumer group or nil to look in all
34
+ # @return [Array<Karafka::Routing::SubscriptionGroup>] requested subscription groups
35
+ def karafka_consumer_find_subscription_groups(requested_consumer_group)
36
+ if requested_consumer_group && !requested_consumer_group.empty?
37
+ ::Karafka::App
38
+ .subscription_groups
39
+ # Find matching consumer group
40
+ .find { |cg, _sgs| cg.name == requested_consumer_group.to_s }
41
+ # Raise error if not found
42
+ .tap { |cg| cg || raise(Errors::ConsumerGroupNotFound, requested_consumer_group) }
43
+ # Since lookup was on a hash, get the value, that is subscription groups
44
+ .last
45
+ else
46
+ ::Karafka::App
47
+ .subscription_groups
48
+ .values
49
+ .flatten
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'karafka/testing/errors'
4
+ require 'karafka/testing/helpers'
4
5
  require 'karafka/testing/spec_consumer_client'
5
6
  require 'karafka/testing/spec_producer_client'
6
7
  require 'karafka/testing/minitest/proxy'
@@ -53,7 +54,7 @@ module Karafka
53
54
  # @example Creates a consumer instance with settings for `my_requested_topic`
54
55
  # consumer = @karafka.consumer_for(:my_requested_topic)
55
56
  def _karafka_consumer_for(requested_topic, requested_consumer_group = nil)
56
- selected_topics = _karafka_consumer_find_candidate_topics(
57
+ selected_topics = Testing::Helpers.karafka_consumer_find_candidate_topics(
57
58
  requested_topic.to_s,
58
59
  requested_consumer_group.to_s
59
60
  )
@@ -166,47 +167,6 @@ module Karafka
166
167
  @consumer.instance_variable_set('@used', true)
167
168
  @consumer
168
169
  end
169
-
170
- # Finds all the routing topics matching requested topic within all topics or within
171
- # provided consumer group based on name
172
- #
173
- # @param requested_topic [String] requested topic name
174
- # @param requested_consumer_group [String] requested consumer group or nil to look in all
175
- # @return [Array<Karafka::Routing::Topic>] all matching topics
176
- #
177
- # @note Since we run the lookup on subscription groups, the search will automatically
178
- # expand with matching patterns
179
- def _karafka_consumer_find_candidate_topics(requested_topic, requested_consumer_group)
180
- _karafka_consumer_find_subscription_groups(requested_consumer_group)
181
- .map(&:topics)
182
- .filter_map do |topics|
183
- topics.find(requested_topic.to_s)
184
- rescue Karafka::Errors::TopicNotFoundError
185
- nil
186
- end
187
- end
188
-
189
- # Finds subscription groups from the requested consumer group or selects all if no
190
- # consumer group specified
191
- # @param requested_consumer_group [String] requested consumer group or nil to look in all
192
- # @return [Array<Karafka::Routing::SubscriptionGroup>] requested subscription groups
193
- def _karafka_consumer_find_subscription_groups(requested_consumer_group)
194
- if requested_consumer_group && !requested_consumer_group.empty?
195
- ::Karafka::App
196
- .subscription_groups
197
- # Find matching consumer group
198
- .find { |cg, _sgs| cg.name == requested_consumer_group.to_s }
199
- # Raise error if not found
200
- .tap { |cg| cg || raise(Errors::ConsumerGroupNotFound, requested_consumer_group) }
201
- # Since lookup was on a hash, get the value, that is subscription groups
202
- .last
203
- else
204
- ::Karafka::App
205
- .subscription_groups
206
- .values
207
- .flatten
208
- end
209
- end
210
170
  end
211
171
  end
212
172
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'waterdrop'
4
4
  require 'karafka/testing/errors'
5
+ require 'karafka/testing/helpers'
5
6
  require 'karafka/testing/spec_consumer_client'
6
7
  require 'karafka/testing/spec_producer_client'
7
8
  require 'karafka/testing/rspec/proxy'
@@ -57,7 +58,7 @@ module Karafka
57
58
  # subject(:consumer) { karafka.consumer_for(:my_requested_topic) }
58
59
  # end
59
60
  def _karafka_consumer_for(requested_topic, requested_consumer_group = nil)
60
- selected_topics = _karafka_consumer_find_candidate_topics(
61
+ selected_topics = Testing::Helpers.karafka_consumer_find_candidate_topics(
61
62
  requested_topic.to_s,
62
63
  requested_consumer_group.to_s
63
64
  )
@@ -176,47 +177,6 @@ module Karafka
176
177
  consumer.instance_variable_set('@used', true)
177
178
  consumer
178
179
  end
179
-
180
- # Finds all the routing topics matching requested topic within all topics or within
181
- # provided consumer group based on name
182
- #
183
- # @param requested_topic [String] requested topic name
184
- # @param requested_consumer_group [String] requested consumer group or nil to look in all
185
- # @return [Array<Karafka::Routing::Topic>] all matching topics
186
- #
187
- # @note Since we run the lookup on subscription groups, the search will automatically
188
- # expand with matching patterns
189
- def _karafka_consumer_find_candidate_topics(requested_topic, requested_consumer_group)
190
- _karafka_consumer_find_subscription_groups(requested_consumer_group)
191
- .map(&:topics)
192
- .filter_map do |topics|
193
- topics.find(requested_topic.to_s)
194
- rescue Karafka::Errors::TopicNotFoundError
195
- nil
196
- end
197
- end
198
-
199
- # Finds subscription groups from the requested consumer group or selects all if no
200
- # consumer group specified
201
- # @param requested_consumer_group [String] requested consumer group or nil to look in all
202
- # @return [Array<Karafka::Routing::SubscriptionGroup>] requested subscription groups
203
- def _karafka_consumer_find_subscription_groups(requested_consumer_group)
204
- if requested_consumer_group && !requested_consumer_group.empty?
205
- ::Karafka::App
206
- .subscription_groups
207
- # Find matching consumer group
208
- .find { |cg, _sgs| cg.name == requested_consumer_group.to_s }
209
- # Raise error if not found
210
- .tap { |cg| cg || raise(Errors::ConsumerGroupNotFound, requested_consumer_group) }
211
- # Since lookup was on a hash, get the value, that is subscription groups
212
- .last
213
- else
214
- ::Karafka::App
215
- .subscription_groups
216
- .values
217
- .flatten
218
- end
219
- end
220
180
  end
221
181
  end
222
182
  end
@@ -4,6 +4,6 @@
4
4
  module Karafka
5
5
  module Testing
6
6
  # Current version of gem. It should match Karafka framework version
7
- VERSION = '2.3.2'
7
+ VERSION = '2.3.3'
8
8
  end
9
9
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka-testing
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -35,7 +35,7 @@ cert_chain:
35
35
  AnG1dJU+yL2BK7vaVytLTstJME5mepSZ46qqIJXMuWob/YPDmVaBF39TDSG9e34s
36
36
  msG3BiCqgOgHAnL23+CN3Rt8MsuRfEtoTKpJVcCfoEoNHOkc
37
37
  -----END CERTIFICATE-----
38
- date: 2024-04-11 00:00:00.000000000 Z
38
+ date: 2024-04-22 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: karafka
@@ -97,6 +97,7 @@ files:
97
97
  - lib/karafka-testing.rb
98
98
  - lib/karafka/testing.rb
99
99
  - lib/karafka/testing/errors.rb
100
+ - lib/karafka/testing/helpers.rb
100
101
  - lib/karafka/testing/minitest/helpers.rb
101
102
  - lib/karafka/testing/minitest/proxy.rb
102
103
  - lib/karafka/testing/rspec/helpers.rb
metadata.gz.sig CHANGED
Binary file