karafka-testing 2.4.0.rc1 → 2.4.0.rc2

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: 587bb151db13812b7c26215c9357264f21a3357448fffe542363042db19c7744
4
- data.tar.gz: 2c624b601afc5384ae7ce43bf6b0ac19f27a8ec8b00aacd796c33da5e19fdd40
3
+ metadata.gz: 91dfd9d61d189ef4382255dd90805291525c7ce596002f5932eddbf60d0ed4d4
4
+ data.tar.gz: c288612346f823379c454a2de964c6600a4705a99704c2261b78e8f685f33068
5
5
  SHA512:
6
- metadata.gz: c70be00aeb884026f00025dc207219761ba5374e91980d89fffff2b4a76eef26098896cf60860d8f9dc088e8606569ab23c3b6ad6b75e31225ca6ad51f7296c4
7
- data.tar.gz: 344b7a3176b89a1882656eb730a458093b580e25a4e6363472b3dd95f200999697c5216814fbecb4c214a50f231e6e32f46cca1af6c90a6274ce4b6b09f19e4d
6
+ metadata.gz: 49458d3a51b4d8ba2a6b073c67dd43a85d1987aa9a300a1047a5268d6f61ae85d4c60a587fe9e8078bec0c61a900b129a8272a931a81fef3f017d548d04ce83b
7
+ data.tar.gz: 27e88641a3c2b0795731bebddf56bb5a81159730152c8fb3859543af5dcdb8bca9f762e4edaaafee931ef8cfc6d18f62c44a2993c321d44b104160826922d974
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  ## 2.4.0 (Unreleased)
4
4
  - **[Breaking]** Drop Ruby `2.7` support.
5
+ - [Refactor] Extract common components for Minitest and RSpec.
5
6
  - [Fix] Support again `require: false` on gem loading.
7
+ - [Fix] Fix a case where multiplexed SG would fail with `TopicInManyConsumerGroupsError`
6
8
 
7
9
  ## 2.3.2 (2024-04-03)
8
10
  - [Enhancement] Support `Minitest::Spec`.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-testing (2.4.0.rc1)
4
+ karafka-testing (2.4.0.rc2)
5
5
  karafka (>= 2.4.0.beta1, < 2.5.0)
6
6
  waterdrop (>= 2.7.0.rc1)
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
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'karafka/testing'
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/minitest/proxy'
@@ -56,7 +57,7 @@ module Karafka
56
57
  # @example Creates a consumer instance with settings for `my_requested_topic`
57
58
  # consumer = @karafka.consumer_for(:my_requested_topic)
58
59
  def _karafka_consumer_for(requested_topic, requested_consumer_group = nil)
59
- selected_topics = _karafka_consumer_find_candidate_topics(
60
+ selected_topics = Testing::Helpers.karafka_consumer_find_candidate_topics(
60
61
  requested_topic.to_s,
61
62
  requested_consumer_group.to_s
62
63
  )
@@ -169,48 +170,6 @@ module Karafka
169
170
  @consumer.instance_variable_set('@used', true)
170
171
  @consumer
171
172
  end
172
-
173
- # Finds all the routing topics matching requested topic within all topics or within
174
- # provided consumer group based on name
175
- #
176
- # @param requested_topic [String] requested topic name
177
- # @param requested_consumer_group [String] requested consumer group or nil to look in all
178
- # @return [Array<Karafka::Routing::Topic>] all matching topics
179
- #
180
- # @note Since we run the lookup on subscription groups, the search will automatically
181
- # expand with matching patterns
182
- def _karafka_consumer_find_candidate_topics(requested_topic, requested_consumer_group)
183
- _karafka_consumer_find_subscription_groups(requested_consumer_group)
184
- .map(&:topics)
185
- .filter_map do |topics|
186
- topics.find(requested_topic.to_s)
187
- rescue Karafka::Errors::TopicNotFoundError
188
- nil
189
- end
190
- .uniq(&:consumer_group)
191
- end
192
-
193
- # Finds subscription groups from the requested consumer group or selects all if no
194
- # consumer group specified
195
- # @param requested_consumer_group [String] requested consumer group or nil to look in all
196
- # @return [Array<Karafka::Routing::SubscriptionGroup>] requested subscription groups
197
- def _karafka_consumer_find_subscription_groups(requested_consumer_group)
198
- if requested_consumer_group && !requested_consumer_group.empty?
199
- ::Karafka::App
200
- .subscription_groups
201
- # Find matching consumer group
202
- .find { |cg, _sgs| cg.name == requested_consumer_group.to_s }
203
- # Raise error if not found
204
- .tap { |cg| cg || raise(Errors::ConsumerGroupNotFound, requested_consumer_group) }
205
- # Since lookup was on a hash, get the value, that is subscription groups
206
- .last
207
- else
208
- ::Karafka::App
209
- .subscription_groups
210
- .values
211
- .flatten
212
- end
213
- end
214
173
  end
215
174
  end
216
175
  end
@@ -3,6 +3,7 @@
3
3
  require 'waterdrop'
4
4
  require 'karafka/testing'
5
5
  require 'karafka/testing/errors'
6
+ require 'karafka/testing/helpers'
6
7
  require 'karafka/testing/spec_consumer_client'
7
8
  require 'karafka/testing/spec_producer_client'
8
9
  require 'karafka/testing/rspec/proxy'
@@ -60,7 +61,7 @@ module Karafka
60
61
  # subject(:consumer) { karafka.consumer_for(:my_requested_topic) }
61
62
  # end
62
63
  def _karafka_consumer_for(requested_topic, requested_consumer_group = nil)
63
- selected_topics = _karafka_consumer_find_candidate_topics(
64
+ selected_topics = Testing::Helpers.karafka_consumer_find_candidate_topics(
64
65
  requested_topic.to_s,
65
66
  requested_consumer_group.to_s
66
67
  )
@@ -179,48 +180,6 @@ module Karafka
179
180
  consumer.instance_variable_set('@used', true)
180
181
  consumer
181
182
  end
182
-
183
- # Finds all the routing topics matching requested topic within all topics or within
184
- # provided consumer group based on name
185
- #
186
- # @param requested_topic [String] requested topic name
187
- # @param requested_consumer_group [String] requested consumer group or nil to look in all
188
- # @return [Array<Karafka::Routing::Topic>] all matching topics
189
- #
190
- # @note Since we run the lookup on subscription groups, the search will automatically
191
- # expand with matching patterns
192
- def _karafka_consumer_find_candidate_topics(requested_topic, requested_consumer_group)
193
- _karafka_consumer_find_subscription_groups(requested_consumer_group)
194
- .map(&:topics)
195
- .filter_map do |topics|
196
- topics.find(requested_topic.to_s)
197
- rescue Karafka::Errors::TopicNotFoundError
198
- nil
199
- end
200
- .uniq(&:consumer_group)
201
- end
202
-
203
- # Finds subscription groups from the requested consumer group or selects all if no
204
- # consumer group specified
205
- # @param requested_consumer_group [String] requested consumer group or nil to look in all
206
- # @return [Array<Karafka::Routing::SubscriptionGroup>] requested subscription groups
207
- def _karafka_consumer_find_subscription_groups(requested_consumer_group)
208
- if requested_consumer_group && !requested_consumer_group.empty?
209
- ::Karafka::App
210
- .subscription_groups
211
- # Find matching consumer group
212
- .find { |cg, _sgs| cg.name == requested_consumer_group.to_s }
213
- # Raise error if not found
214
- .tap { |cg| cg || raise(Errors::ConsumerGroupNotFound, requested_consumer_group) }
215
- # Since lookup was on a hash, get the value, that is subscription groups
216
- .last
217
- else
218
- ::Karafka::App
219
- .subscription_groups
220
- .values
221
- .flatten
222
- end
223
- end
224
183
  end
225
184
  end
226
185
  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.4.0.rc1'
7
+ VERSION = '2.4.0.rc2'
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.4.0.rc1
4
+ version: 2.4.0.rc2
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-10 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