karafka-testing 2.3.3 → 2.4.0.beta1

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: 91a12f6c61514bc890bdfd8f6c91e1a834dd1516299f8a6d421c54037d3b55b3
4
- data.tar.gz: 70d467cb5994992d5a3046511bca0676fabc673b2b36c45d366b98d6aeeeae06
3
+ metadata.gz: e62624d40d7aa454841a212de1beaf67127ef06873bd0604dcbfe4747a397cf5
4
+ data.tar.gz: 2e031857e92ce50f55ea24e3cb32309a070c11ea930de263f05ec9c82f24992d
5
5
  SHA512:
6
- metadata.gz: ebb18327ff48e4443377a54a09d35611c84f6806bc298ceb0792d1b2862f7f1c35e2c528bdb8b7e611d61998201f851dc8648530d398fdbbd33ec504d7fedae7
7
- data.tar.gz: 9898b5f1bd9264b696361cfd60039226864eb26743722c21a251fad26d2bd9d633b9be0cadcf62dbc7638a5287b69a0aaf720b12ad70595cc03c6bc1c4fe920f
6
+ metadata.gz: b2c5398aa8d03a31499a29b60f3e45456e6151cbbd57f979dac9ddc6aea283e5fb6b0613a1df336fb3d46284af16861125a7df980c9701ace2af2d2d3ef8336f
7
+ data.tar.gz: f32201af31b9e0840ce41e7c17a16a64b7fedfb99a4cb1815f2b18a1fa45bed474eb9dc02e3b68e504a0d2be2191a141e64ed52fad25fee9ba86e42030250a0f
checksums.yaml.gz.sig CHANGED
Binary file
@@ -22,7 +22,6 @@ jobs:
22
22
  - '3.2'
23
23
  - '3.1'
24
24
  - '3.0'
25
- - '2.7'
26
25
  include:
27
26
  - ruby: '3.3'
28
27
  coverage: 'true'
@@ -40,24 +39,14 @@ jobs:
40
39
 
41
40
  - name: Install latest bundler
42
41
  run: |
43
- if [[ "$(ruby -v | awk '{print $2}')" == 2.7.8* ]]; then
44
- gem install bundler -v 2.4.22 --no-document
45
- bundle config set version 2.4.22
46
- gem update --system 3.4.22 --no-document
47
- else
48
- gem install bundler --no-document
49
- gem update --system --no-document
50
- fi
42
+ gem install bundler --no-document
43
+ gem update --system --no-document
51
44
 
52
45
  bundle config set without 'tools benchmarks docs'
53
46
 
54
47
  - name: Bundle install
55
48
  run: |
56
- if [[ "$(ruby -v | awk '{print $2}')" == 2.7.8* ]]; then
57
- BUNDLER_VERSION=2.4.22 bundle install --jobs 4 --retry 3
58
- else
59
- bundle install --jobs 4 --retry 3
60
- fi
49
+ bundle install --jobs 4 --retry 3
61
50
 
62
51
  diffend:
63
52
  runs-on: ubuntu-latest
data/CHANGELOG.md CHANGED
@@ -1,11 +1,8 @@
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
-
7
- ## 2.3.2 (2024-04-03)
8
- - [Enhancement] Support `Minitest::Spec`.
3
+ ## 2.4.0 (Unreleased)
4
+ - **[Breaking]** Drop Ruby `2.7` support.
5
+ - [Fix] Support again `require: false` on gem loading.
9
6
 
10
7
  ## 2.3.1 (2024-03-07)
11
8
  - [Enhancement] Prevent usage of testing when Karafka is not loaded.
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-testing (2.3.3)
5
- karafka (>= 2.3.0, < 2.4.0)
6
- waterdrop (>= 2.6.12)
4
+ karafka-testing (2.4.0.beta1)
5
+ karafka (>= 2.3.0, < 2.5.0)
6
+ waterdrop (>= 2.7.0.beta2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -13,16 +13,16 @@ GEM
13
13
  karafka-core (>= 2.3.0, < 2.4.0)
14
14
  waterdrop (>= 2.6.12, < 3.0.0)
15
15
  zeitwerk (~> 2.3)
16
- karafka-core (2.3.0)
17
- karafka-rdkafka (>= 0.14.8, < 0.15.0)
18
- karafka-rdkafka (0.14.10)
16
+ karafka-core (2.4.0.beta2)
17
+ karafka-rdkafka (>= 0.15.0.beta3, < 0.16.0)
18
+ karafka-rdkafka (0.15.0.beta3)
19
19
  ffi (~> 1.15)
20
20
  mini_portile2 (~> 2.6)
21
21
  rake (> 12)
22
22
  mini_portile2 (2.8.5)
23
23
  rake (13.1.0)
24
- waterdrop (2.6.14)
25
- karafka-core (>= 2.2.3, < 3.0.0)
24
+ waterdrop (2.7.0.beta2)
25
+ karafka-core (>= 2.4.0.beta2, < 3.0.0)
26
26
  zeitwerk (~> 2.3)
27
27
  zeitwerk (2.6.13)
28
28
 
@@ -24,8 +24,10 @@ Gem::Specification.new do |spec|
24
24
  spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
25
25
  end
26
26
 
27
- spec.add_dependency 'karafka', '>= 2.3.0', '< 2.4.0'
28
- spec.add_dependency 'waterdrop', '>= 2.6.12'
27
+ spec.add_dependency 'karafka', '>= 2.3.0', '< 2.5.0'
28
+ spec.add_dependency 'waterdrop', '>= 2.7.0.beta2'
29
+
30
+ spec.required_ruby_version = '>= 3.0.0'
29
31
 
30
32
  spec.metadata = {
31
33
  'funding_uri' => 'https://karafka.io/#become-pro',
@@ -15,7 +15,17 @@ module Karafka
15
15
  TopicInManyConsumerGroupsError = Class.new(BaseError)
16
16
 
17
17
  # Raised when you requested a topic from a consumer group that does not exist
18
- ConsumerGroupNotFound = Class.new(BaseError)
18
+ ConsumerGroupNotFoundError = Class.new(BaseError)
19
+
20
+ # Raised when trying to use testing without Karafka app being visible
21
+ # If you are seeing this error, then you tried to use testing helpers without Karafka being
22
+ # loaded prior to this happening.
23
+ KarafkaNotLoadedError = Class.new(BaseError)
24
+
25
+ # Raised when there is an attempt to use the testing primitives without Karafka app being
26
+ # configured. Prior to initialization process, most of config values are nils, etc and
27
+ # mocks will not work.
28
+ KarafkaNotInitializedError = Class.new(BaseError)
19
29
  end
20
30
  end
21
31
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'karafka/testing'
3
4
  require 'karafka/testing/errors'
4
- require 'karafka/testing/helpers'
5
5
  require 'karafka/testing/spec_consumer_client'
6
6
  require 'karafka/testing/spec_producer_client'
7
7
  require 'karafka/testing/minitest/proxy'
@@ -17,25 +17,19 @@ module Karafka
17
17
  # Adds all the needed extra functionalities to the minitest group
18
18
  # @param base [Class] Minitest example group we want to extend
19
19
  def included(base)
20
- eval_flow = lambda do
21
- @karafka = Karafka::Testing::Minitest::Proxy.new(self)
22
- @_karafka_consumer_messages = []
23
- @_karafka_consumer_client = Karafka::Testing::SpecConsumerClient.new
24
- @_karafka_producer_client = Karafka::Testing::SpecProducerClient.new(self)
20
+ base.class_eval do
21
+ setup do
22
+ Karafka::Testing.ensure_karafka_initialized!
25
23
 
26
- @_karafka_consumer_messages.clear
27
- @_karafka_producer_client.reset
24
+ @karafka = Karafka::Testing::Minitest::Proxy.new(self)
25
+ @_karafka_consumer_messages = []
26
+ @_karafka_consumer_client = Karafka::Testing::SpecConsumerClient.new
27
+ @_karafka_producer_client = Karafka::Testing::SpecProducerClient.new(self)
28
28
 
29
- Karafka.producer.stubs(:client).returns(@_karafka_producer_client)
30
- end
29
+ @_karafka_consumer_messages.clear
30
+ @_karafka_producer_client.reset
31
31
 
32
- if base.to_s == 'Minitest::Spec'
33
- base.class_eval do
34
- before(&eval_flow)
35
- end
36
- else
37
- base.class_eval do
38
- setup(&eval_flow)
32
+ Karafka.producer.stubs(:client).returns(@_karafka_producer_client)
39
33
  end
40
34
  end
41
35
  end
@@ -54,7 +48,7 @@ module Karafka
54
48
  # @example Creates a consumer instance with settings for `my_requested_topic`
55
49
  # consumer = @karafka.consumer_for(:my_requested_topic)
56
50
  def _karafka_consumer_for(requested_topic, requested_consumer_group = nil)
57
- selected_topics = Testing::Helpers.karafka_consumer_find_candidate_topics(
51
+ selected_topics = _karafka_consumer_find_candidate_topics(
58
52
  requested_topic.to_s,
59
53
  requested_consumer_group.to_s
60
54
  )
@@ -136,10 +130,10 @@ module Karafka
136
130
  # @return [Hash] message default options
137
131
  def _karafka_message_metadata_defaults
138
132
  {
139
- deserializer: @consumer.topic.deserializer,
133
+ deserializers: @consumer.topic.deserializers,
140
134
  timestamp: Time.now,
141
- headers: {},
142
- key: nil,
135
+ raw_headers: {},
136
+ raw_key: nil,
143
137
  offset: @_karafka_consumer_messages.size,
144
138
  partition: 0,
145
139
  received_at: Time.now,
@@ -167,6 +161,48 @@ module Karafka
167
161
  @consumer.instance_variable_set('@used', true)
168
162
  @consumer
169
163
  end
164
+
165
+ # Finds all the routing topics matching requested topic within all topics or within
166
+ # provided consumer group based on name
167
+ #
168
+ # @param requested_topic [String] requested topic name
169
+ # @param requested_consumer_group [String] requested consumer group or nil to look in all
170
+ # @return [Array<Karafka::Routing::Topic>] all matching topics
171
+ #
172
+ # @note Since we run the lookup on subscription groups, the search will automatically
173
+ # expand with matching patterns
174
+ def _karafka_consumer_find_candidate_topics(requested_topic, requested_consumer_group)
175
+ _karafka_consumer_find_subscription_groups(requested_consumer_group)
176
+ .map(&:topics)
177
+ .filter_map do |topics|
178
+ topics.find(requested_topic.to_s)
179
+ rescue Karafka::Errors::TopicNotFoundError
180
+ nil
181
+ end
182
+ .uniq(&:consumer_group)
183
+ end
184
+
185
+ # Finds subscription groups from the requested consumer group or selects all if no
186
+ # consumer group specified
187
+ # @param requested_consumer_group [String] requested consumer group or nil to look in all
188
+ # @return [Array<Karafka::Routing::SubscriptionGroup>] requested subscription groups
189
+ def _karafka_consumer_find_subscription_groups(requested_consumer_group)
190
+ if requested_consumer_group && !requested_consumer_group.empty?
191
+ ::Karafka::App
192
+ .subscription_groups
193
+ # Find matching consumer group
194
+ .find { |cg, _sgs| cg.name == requested_consumer_group.to_s }
195
+ # Raise error if not found
196
+ .tap { |cg| cg || raise(Errors::ConsumerGroupNotFound, requested_consumer_group) }
197
+ # Since lookup was on a hash, get the value, that is subscription groups
198
+ .last
199
+ else
200
+ ::Karafka::App
201
+ .subscription_groups
202
+ .values
203
+ .flatten
204
+ end
205
+ end
170
206
  end
171
207
  end
172
208
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'waterdrop'
4
+ require 'karafka/testing'
4
5
  require 'karafka/testing/errors'
5
- require 'karafka/testing/helpers'
6
6
  require 'karafka/testing/spec_consumer_client'
7
7
  require 'karafka/testing/spec_producer_client'
8
8
  require 'karafka/testing/rspec/proxy'
@@ -31,6 +31,8 @@ module Karafka
31
31
  base.let(:_karafka_producer_client) { Karafka::Testing::SpecProducerClient.new(self) }
32
32
 
33
33
  base.prepend_before do
34
+ Karafka::Testing.ensure_karafka_initialized!
35
+
34
36
  _karafka_consumer_messages.clear
35
37
  _karafka_producer_client.reset
36
38
 
@@ -58,7 +60,7 @@ module Karafka
58
60
  # subject(:consumer) { karafka.consumer_for(:my_requested_topic) }
59
61
  # end
60
62
  def _karafka_consumer_for(requested_topic, requested_consumer_group = nil)
61
- selected_topics = Testing::Helpers.karafka_consumer_find_candidate_topics(
63
+ selected_topics = _karafka_consumer_find_candidate_topics(
62
64
  requested_topic.to_s,
63
65
  requested_consumer_group.to_s
64
66
  )
@@ -145,10 +147,10 @@ module Karafka
145
147
  # @return [Hash] message default options
146
148
  def _karafka_message_metadata_defaults
147
149
  {
148
- deserializer: consumer.topic.deserializer,
150
+ deserializers: consumer.topic.deserializers,
149
151
  timestamp: Time.now,
150
- headers: {},
151
- key: nil,
152
+ raw_headers: {},
153
+ raw_key: nil,
152
154
  offset: _karafka_consumer_messages.size,
153
155
  partition: 0,
154
156
  received_at: Time.now,
@@ -177,6 +179,48 @@ module Karafka
177
179
  consumer.instance_variable_set('@used', true)
178
180
  consumer
179
181
  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
180
224
  end
181
225
  end
182
226
  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.3'
7
+ VERSION = '2.4.0.beta1'
8
8
  end
9
9
  end
@@ -4,5 +4,32 @@
4
4
  module Karafka
5
5
  # Testing lib module
6
6
  module Testing
7
+ class << self
8
+ # Makes sure, that we do not use the testing stubs, etc when Karafka app is not loaded
9
+ #
10
+ # You should never use karafka-testing primitives when framework is not loaded because
11
+ # testing lib stubs certain pieces of Karafka that need to be initialized.
12
+ def ensure_karafka_loaded!
13
+ return if ::Karafka.const_defined?('App', false)
14
+
15
+ raise(
16
+ Karafka::Testing::Errors::KarafkaNotLoadedError,
17
+ 'Make sure to load Karafka framework prior to usage of the testing components.'
18
+ )
19
+ end
20
+
21
+ # If you do not initialize Karafka always within your specs, do not include/use this lib
22
+ # in places where Karafka would not be loaded.
23
+ def ensure_karafka_initialized!
24
+ ensure_karafka_loaded!
25
+
26
+ return unless Karafka::App.initializing?
27
+
28
+ raise(
29
+ Karafka::Testing::Errors::KarafkaNotInitializedError,
30
+ 'Make sure to initialize Karafka framework prior to usage of the testing components.'
31
+ )
32
+ end
33
+ end
7
34
  end
8
35
  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.3
4
+ version: 2.4.0.beta1
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-22 00:00:00.000000000 Z
38
+ date: 2024-03-27 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: karafka
@@ -46,7 +46,7 @@ dependencies:
46
46
  version: 2.3.0
47
47
  - - "<"
48
48
  - !ruby/object:Gem::Version
49
- version: 2.4.0
49
+ version: 2.5.0
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,21 +56,21 @@ dependencies:
56
56
  version: 2.3.0
57
57
  - - "<"
58
58
  - !ruby/object:Gem::Version
59
- version: 2.4.0
59
+ version: 2.5.0
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: waterdrop
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: 2.6.12
66
+ version: 2.7.0.beta2
67
67
  type: :runtime
68
68
  prerelease: false
69
69
  version_requirements: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: 2.6.12
73
+ version: 2.7.0.beta2
74
74
  description: Library which provides helpers for easier Karafka consumers tests
75
75
  email:
76
76
  - contact@karafka.io
@@ -97,7 +97,6 @@ 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
101
100
  - lib/karafka/testing/minitest/helpers.rb
102
101
  - lib/karafka/testing/minitest/proxy.rb
103
102
  - lib/karafka/testing/rspec/helpers.rb
@@ -125,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
124
  requirements:
126
125
  - - ">="
127
126
  - !ruby/object:Gem::Version
128
- version: '0'
127
+ version: 3.0.0
129
128
  required_rubygems_version: !ruby/object:Gem::Requirement
130
129
  requirements:
131
130
  - - ">="
metadata.gz.sig CHANGED
Binary file
@@ -1,55 +0,0 @@
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