karafka-testing 2.0.5 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 513e1bb6f2a9ac5806fc7df36f788f4ba1b1f72286110e0584ad882d347453fe
4
- data.tar.gz: a758a804787420eea61375763bcad90a6c2033426d46f8b07707fc5c22d9de72
3
+ metadata.gz: 053ac6d1b86ca621030d7d73ad5e8c629a8b3c4ebf05c83ab89646772edf6565
4
+ data.tar.gz: 3c8182120690c121f41ea395ddef68b35ef18af9a4a448b106dc1efbd45cb5d2
5
5
  SHA512:
6
- metadata.gz: e313af611899b8a3b47791d63694b24612bd97b27dde6262b929a7af315b64c0c2a1e0fd0b22fe25838d41b3c592c302b610e67031b44b27f08ee2daf78a4705
7
- data.tar.gz: 18d88784906a4d19a33dab5ceca6236c1720d488c58b56e324464eb5730096c5f3bcfcfa3b8481fe4db974c10a2d294d3c91a50b9d7c030e28a0314531c1798c
6
+ metadata.gz: 8dc3c9437a06c83b85329170d670172152b17c0057b6a40655630032d885f7a743306eaafdd737ac7a65db4a0a9aa3da2d53f2aac2659587a31b8b3e9a3cb16e
7
+ data.tar.gz: 67cbaef664caedeadb54cd8fa1ccc3be917fbc17f5cfe34b22a1ad8ee259937f652de68e16dc870ef7b490f66ec16856d2de3f3e841075ad17620725e041f329
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1 @@
1
+ custom: ['https://karafka.io/#become-pro']
@@ -16,14 +16,15 @@ jobs:
16
16
  fail-fast: false
17
17
  matrix:
18
18
  ruby:
19
+ - '3.2'
19
20
  - '3.1'
20
21
  - '3.0'
21
22
  - '2.7'
22
23
  include:
23
- - ruby: '3.1'
24
+ - ruby: '3.2'
24
25
  coverage: 'true'
25
26
  steps:
26
- - uses: actions/checkout@v2
27
+ - uses: actions/checkout@v3
27
28
  - name: Install package dependencies
28
29
  run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
29
30
  - name: Set up Ruby
@@ -42,13 +43,13 @@ jobs:
42
43
  strategy:
43
44
  fail-fast: false
44
45
  steps:
45
- - uses: actions/checkout@v2
46
+ - uses: actions/checkout@v3
46
47
  with:
47
48
  fetch-depth: 0
48
49
  - name: Set up Ruby
49
50
  uses: ruby/setup-ruby@v1
50
51
  with:
51
- ruby-version: 3.1
52
+ ruby-version: 3.2
52
53
  - name: Install latest bundler
53
54
  run: gem install bundler --no-document
54
55
  - name: Install Diffend plugin
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.1.2
1
+ 3.2.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # Karafka Test gem changelog
2
2
 
3
+ ## 2.1.4 (2023-06-20)
4
+ - [Fix] Fix invalid consumer group assignment for consumers created for non-default consumer group when same topic is being used multiple times.
5
+
6
+ ## 2.1.3 (2023-06-19)
7
+ - [Enhancement] Align with Karafka `2.1.5` API.
8
+
9
+ ## 2.1.2 (2023-06-13)
10
+ - [Enhancement] Depend on WaterDrop `>=` `2.6.0` directly and not via Karafka to make sure correct version is used.
11
+ - [Fix] Use proper WaterDrop `>=` `2.6.0` buffered client reference.
12
+
13
+ ## 2.1.1 (2023-06-07)
14
+ - [Enhancement] Support WaterDrop stubs with Mocha.
15
+
16
+ ## 2.1.0 (2023-05-22)
17
+ - [Maintenance] Align Karafka expectations to match `2.1.0`.
18
+
19
+ ## 2.0.11 (2023-04-13)
20
+ - Align metadata builder format with Karafka `2.0.40`.
21
+
22
+ ## 2.0.10 (2023-04-11)
23
+ - Align with changes in Karafka `2.0.39`
24
+ - Replace direct `described_class` reference for consumer building with `topic.consumer` Karafka routing based one. This change will allow for usage of `karafka.consumer_for` from any specs.
25
+
26
+ ## 2.0.9 (2023-02-10)
27
+ - Inject consumer strategy to the test consumer instance.
28
+
29
+ ## 2.0.8 (2022-11-03)
30
+ - Do not lock Ruby and rely on `karafka-core` via `karafka`.
31
+ - Due to changes in the engine, lock to `2.0.20`.
32
+
33
+ ## 2.0.7 (2022-11-03)
34
+ - Release version with cert with valid access permissions (#114).
35
+
36
+ ## 2.0.6 (2022-10-26)
37
+ - Replace the `subject` reference with named `consumer` reference.
38
+ - Do not forward sent messages to `consumer` unless it's a Karafka consumer.
39
+
3
40
  ## 2.0.5 (2022-10-19)
4
41
  - Fix for: Test event production without defining a subject (#102)
5
42
 
data/Gemfile.lock CHANGED
@@ -1,34 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-testing (2.0.5)
5
- karafka (>= 2.0, < 3.0.0)
4
+ karafka-testing (2.1.4)
5
+ karafka (>= 2.1.5, < 3.0.0)
6
+ waterdrop (>= 2.6.1)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- concurrent-ruby (1.1.10)
11
+ concurrent-ruby (1.2.2)
11
12
  ffi (1.15.5)
12
- karafka (2.0.14)
13
- karafka-core (>= 2.0.2, < 3.0.0)
14
- rdkafka (>= 0.12)
13
+ karafka (2.1.5)
14
+ karafka-core (>= 2.1.0, < 2.2.0)
15
15
  thor (>= 0.20)
16
- waterdrop (>= 2.4.1, < 3.0.0)
16
+ waterdrop (>= 2.6.1, < 3.0.0)
17
17
  zeitwerk (~> 2.3)
18
- karafka-core (2.0.3)
18
+ karafka-core (2.1.0)
19
19
  concurrent-ruby (>= 1.1)
20
- mini_portile2 (2.8.0)
21
- rake (13.0.6)
22
- rdkafka (0.12.0)
20
+ karafka-rdkafka (>= 0.13.0, < 0.14.0)
21
+ karafka-rdkafka (0.13.0)
23
22
  ffi (~> 1.15)
24
23
  mini_portile2 (~> 2.6)
25
24
  rake (> 12)
25
+ mini_portile2 (2.8.1)
26
+ rake (13.0.6)
26
27
  thor (1.2.1)
27
- waterdrop (2.4.2)
28
- karafka-core (>= 2.0.2, < 3.0.0)
29
- rdkafka (>= 0.10)
28
+ waterdrop (2.6.1)
29
+ karafka-core (>= 2.1.0, < 3.0.0)
30
30
  zeitwerk (~> 2.3)
31
- zeitwerk (2.6.1)
31
+ zeitwerk (2.6.7)
32
32
 
33
33
  PLATFORMS
34
34
  arm64-darwin
@@ -38,4 +38,4 @@ DEPENDENCIES
38
38
  karafka-testing!
39
39
 
40
40
  BUNDLED WITH
41
- 2.3.24
41
+ 2.4.12
@@ -20,16 +20,20 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = %w[lib]
21
21
  spec.cert_chain = %w[certs/cert_chain.pem]
22
22
 
23
- spec.required_ruby_version = '>= 2.7'
24
-
25
23
  if $PROGRAM_NAME.end_with?('gem')
26
24
  spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
27
25
  end
28
26
 
29
- spec.add_dependency 'karafka', '>= 2.0', '< 3.0.0'
27
+ spec.add_dependency 'karafka', '>= 2.1.5', '< 3.0.0'
28
+ spec.add_dependency 'waterdrop', '>= 2.6.1'
30
29
 
31
30
  spec.metadata = {
31
+ 'funding_uri' => 'https://karafka.io/#become-pro',
32
+ 'homepage_uri' => 'https://karafka.io',
33
+ 'changelog_uri' => 'https://github.com/karafka/karafka-testing/blob/master/CHANGELOG.md',
34
+ 'bug_tracker_uri' => 'https://github.com/karafka/karafka-testing/issues',
32
35
  'source_code_uri' => 'https://github.com/karafka/karafka-testing',
36
+ 'documentation_uri' => 'https://karafka.io/docs',
33
37
  'rubygems_mfa_required' => 'true'
34
38
  }
35
39
  end
@@ -33,7 +33,11 @@ module Karafka
33
33
  _karafka_consumer_messages.clear
34
34
  _karafka_producer_client.reset
35
35
 
36
- allow(Karafka.producer).to receive(:client).and_return(_karafka_producer_client)
36
+ if Object.const_defined?('Mocha', false)
37
+ Karafka.producer.stubs(:client).returns(_karafka_producer_client)
38
+ else
39
+ allow(Karafka.producer).to receive(:client).and_return(_karafka_producer_client)
40
+ end
37
41
  end
38
42
  end
39
43
  end
@@ -44,7 +48,7 @@ module Karafka
44
48
  # create a consumer instance
45
49
  # @param requested_consumer_group [String, Symbol, nil] optional name of the consumer group
46
50
  # if we have multiple consumer groups listening on the same topic
47
- # @return [Object] described_class instance
51
+ # @return [Object] Karafka consumer instance
48
52
  # @raise [Karafka::Testing::Errors::TopicNotFoundError] raised when we're unable to find
49
53
  # topic that was requested
50
54
  #
@@ -85,13 +89,15 @@ module Karafka
85
89
  # karafka.produce({ 'hello' => 'world' }.to_json, 'partition' => 6)
86
90
  # end
87
91
  def _karafka_add_message_to_consumer_if_needed(message)
88
- # We're interested in adding message to subject only when it is a consumer
92
+ # Consumer needs to be defined in order to pass messages to it
93
+ return unless defined?(consumer)
94
+ # We're interested in adding message to consumer only when it is a Karafka consumer
89
95
  # Users may want to test other things (models producing messages for example) and in
90
- # their case subject will not be a consumer
91
- return unless subject.is_a?(Karafka::BaseConsumer)
96
+ # their case consumer will not be a consumer
97
+ return unless consumer.is_a?(Karafka::BaseConsumer)
92
98
  # We target to the consumer only messages that were produced to it, since specs may also
93
99
  # produce other messages targeting other topics
94
- return unless message[:topic] == subject.topic.name
100
+ return unless message[:topic] == consumer.topic.name
95
101
 
96
102
  # Build message metadata and copy any metadata that would come from the message
97
103
  metadata = _karafka_message_metadata_defaults
@@ -111,12 +117,13 @@ module Karafka
111
117
  # Update batch metadata
112
118
  batch_metadata = Karafka::Messages::Builders::BatchMetadata.call(
113
119
  _karafka_consumer_messages,
114
- subject.topic,
120
+ consumer.topic,
121
+ 0,
115
122
  Time.now
116
123
  )
117
124
 
118
125
  # Update consumer messages batch
119
- subject.messages = Karafka::Messages::Messages.new(
126
+ consumer.messages = Karafka::Messages::Messages.new(
120
127
  _karafka_consumer_messages,
121
128
  batch_metadata
122
129
  )
@@ -128,7 +135,7 @@ module Karafka
128
135
  def _karafka_produce(payload, metadata = {})
129
136
  Karafka.producer.produce_sync(
130
137
  {
131
- topic: subject.topic.name,
138
+ topic: consumer.topic.name,
132
139
  payload: payload
133
140
  }.merge(metadata)
134
141
  )
@@ -144,14 +151,14 @@ module Karafka
144
151
  # @return [Hash] message default options
145
152
  def _karafka_message_metadata_defaults
146
153
  {
147
- deserializer: subject.topic.deserializer,
154
+ deserializer: consumer.topic.deserializer,
148
155
  timestamp: Time.now,
149
156
  headers: {},
150
157
  key: nil,
151
158
  offset: _karafka_consumer_messages.size,
152
159
  partition: 0,
153
160
  received_at: Time.now,
154
- topic: subject.topic.name
161
+ topic: consumer.topic.name
155
162
  }
156
163
  end
157
164
 
@@ -160,11 +167,15 @@ module Karafka
160
167
  # @param topic [Karafka::Routing::Topic] topic for which we want to build the consumer
161
168
  # @return [Object] karafka consumer
162
169
  def _karafka_build_consumer_for(topic)
163
- coordinators = Karafka::Processing::CoordinatorsBuffer.new
170
+ coordinators = Karafka::Processing::CoordinatorsBuffer.new(
171
+ Karafka::Routing::Topics.new([topic])
172
+ )
164
173
 
165
- consumer = described_class.new
166
- consumer.topic = topic
174
+ consumer = topic.consumer.new
167
175
  consumer.producer = Karafka::App.producer
176
+ # Inject appropriate strategy so needed options and components are available
177
+ strategy = Karafka::App.config.internal.processing.strategy_selector.find(topic)
178
+ consumer.singleton_class.include(strategy)
168
179
  consumer.client = _karafka_consumer_client
169
180
  consumer.coordinator = coordinators.find_or_create(topic.name, 0)
170
181
  consumer.coordinator.seek_offset = 0
@@ -12,6 +12,11 @@ module Karafka
12
12
  ].each do |caught_delegator|
13
13
  define_method(caught_delegator) { |*| }
14
14
  end
15
+
16
+ # @return [Boolean] assignments are never lost for specs
17
+ def assignment_lost?
18
+ false
19
+ end
15
20
  end
16
21
  end
17
22
  end
@@ -3,40 +3,21 @@
3
3
  module Karafka
4
4
  module Testing
5
5
  # Spec producer client used to buffer messages that we send out in specs
6
- class SpecProducerClient < ::WaterDrop::Producer::DummyClient
7
- attr_accessor :messages
8
-
9
- # Sync fake response for the message delivery to Kafka, since we do not dispatch anything
10
- class SyncResponse
11
- # @param _args Handler wait arguments (irrelevant as waiting is fake here)
12
- def wait(*_args)
13
- false
14
- end
15
- end
16
-
6
+ class SpecProducerClient < ::WaterDrop::Clients::Buffered
17
7
  # @param rspec [RSpec::Core::ExampleGroup] rspec example we need to hold to trigger actions
18
8
  # on it that are rspec context aware
19
9
  def initialize(rspec)
20
- super()
10
+ super(nil)
21
11
  @rspec = rspec
22
- self.messages = []
23
12
  end
24
13
 
25
14
  # "Produces" message to Kafka. That is, it acknowledges it locally, adds it to the internal
26
15
  # buffer and adds it (if needed) into the current consumer messages buffer
27
16
  # @param message [Hash] `Karafka.producer.produce_sync` message hash
28
17
  def produce(message)
29
- messages << message
30
-
31
18
  @rspec._karafka_add_message_to_consumer_if_needed(message)
32
19
 
33
- SyncResponse.new
34
- end
35
-
36
- # Clears internal buffer
37
- # Used in between specs so messages do not leak out
38
- def reset
39
- messages.clear
20
+ super
40
21
  end
41
22
  end
42
23
  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.0.5'
7
+ VERSION = '2.1.4'
8
8
  end
9
9
  end
data/renovate.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "config:base"
5
+ ]
6
+ }
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.0.5
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -35,7 +35,7 @@ cert_chain:
35
35
  Qf04B9ceLUaC4fPVEz10FyobjaFoY4i32xRto3XnrzeAgfEe4swLq8bQsR3w/EF3
36
36
  MGU0FeSV2Yj7Xc2x/7BzLK8xQn5l7Yy75iPF+KP3vVmDHnNl
37
37
  -----END CERTIFICATE-----
38
- date: 2022-10-19 00:00:00.000000000 Z
38
+ date: 2023-06-20 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: karafka
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '2.0'
46
+ version: 2.1.5
47
47
  - - "<"
48
48
  - !ruby/object:Gem::Version
49
49
  version: 3.0.0
@@ -53,10 +53,24 @@ dependencies:
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: '2.0'
56
+ version: 2.1.5
57
57
  - - "<"
58
58
  - !ruby/object:Gem::Version
59
59
  version: 3.0.0
60
+ - !ruby/object:Gem::Dependency
61
+ name: waterdrop
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 2.6.1
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 2.6.1
60
74
  description: Library which provides helpers for easier Karafka consumers tests
61
75
  email:
62
76
  - contact@karafka.io
@@ -66,6 +80,7 @@ extra_rdoc_files: []
66
80
  files:
67
81
  - ".coditsu/ci.yml"
68
82
  - ".diffend.yml"
83
+ - ".github/FUNDING.yml"
69
84
  - ".github/workflows/ci.yml"
70
85
  - ".gitignore"
71
86
  - ".rspec"
@@ -87,11 +102,17 @@ files:
87
102
  - lib/karafka/testing/spec_consumer_client.rb
88
103
  - lib/karafka/testing/spec_producer_client.rb
89
104
  - lib/karafka/testing/version.rb
105
+ - renovate.json
90
106
  homepage: https://karafka.io
91
107
  licenses:
92
108
  - MIT
93
109
  metadata:
110
+ funding_uri: https://karafka.io/#become-pro
111
+ homepage_uri: https://karafka.io
112
+ changelog_uri: https://github.com/karafka/karafka-testing/blob/master/CHANGELOG.md
113
+ bug_tracker_uri: https://github.com/karafka/karafka-testing/issues
94
114
  source_code_uri: https://github.com/karafka/karafka-testing
115
+ documentation_uri: https://karafka.io/docs
95
116
  rubygems_mfa_required: 'true'
96
117
  post_install_message:
97
118
  rdoc_options: []
@@ -101,14 +122,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
122
  requirements:
102
123
  - - ">="
103
124
  - !ruby/object:Gem::Version
104
- version: '2.7'
125
+ version: '0'
105
126
  required_rubygems_version: !ruby/object:Gem::Requirement
106
127
  requirements:
107
128
  - - ">="
108
129
  - !ruby/object:Gem::Version
109
130
  version: '0'
110
131
  requirements: []
111
- rubygems_version: 3.3.7
132
+ rubygems_version: 3.4.10
112
133
  signing_key:
113
134
  specification_version: 4
114
135
  summary: Library which provides helpers for easier Karafka consumers tests
metadata.gz.sig CHANGED
Binary file