coney_island 0.13.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,84 @@
1
+ require 'test_helper'
2
+
3
+ class JobsCacheTest < MiniTest::Test
4
+ describe ConeyIsland::JobsCache do
5
+ before do
6
+ @instance = ConeyIsland::JobsCache.new
7
+ @instance.flush_jobs
8
+ end
9
+
10
+ after do
11
+ @instance.clear
12
+ end
13
+
14
+ describe :initialize do
15
+ it "assigns RequestStore to the @adapter" do
16
+ assert_equal @instance.instance_variable_get(:@adapter), RequestStore
17
+ end
18
+ end
19
+
20
+ describe :caching_jobs? do
21
+ it "returns false by default" do
22
+ assert_equal @instance.caching_jobs?, false
23
+ end
24
+ end # /caching_jobs?
25
+
26
+ describe :caching_jobs do
27
+ it "calls cache jobs, the block, flush jobs, doesn't change the caching_jobs flag" do
28
+ was_caching = @instance.caching_jobs?
29
+ @instance.expects(:cache_jobs)
30
+ block = -> { puts "Ohai!" }
31
+ block.expects(:call)
32
+ @instance.expects(:flush_jobs)
33
+ @instance.caching_jobs(&block)
34
+ assert_equal was_caching, @instance.caching_jobs?
35
+ end
36
+ end
37
+
38
+ describe :cache_jobs do
39
+ it "flips caching jobs to true" do
40
+ @instance.cache_jobs
41
+ assert_equal @instance.caching_jobs?, true
42
+ end
43
+ end
44
+
45
+ describe :cached_jobs do
46
+ it "returns a Hash" do
47
+ assert_equal @instance.cached_jobs, {}
48
+ end
49
+ end
50
+
51
+ describe :stop_caching_jobs do
52
+ it "flips caching jobs to false" do
53
+ @instance.stop_caching_jobs
54
+ assert_equal @instance.caching_jobs?, false
55
+ end
56
+ end
57
+
58
+ describe :cache_job do
59
+ it "adds a job to the cache with a uuid (highlander not true)" do
60
+ SecureRandom.stub :uuid, "asdf" do
61
+ args = [String, :to_s, { highlander: false }]
62
+ @instance.cache_job(*args)
63
+ assert_equal @instance.cached_jobs["asdf"], args
64
+ end
65
+ end
66
+
67
+ it "adds a job to the cache with an idempotent key (highlander true)" do
68
+ args = [String, :to_s, { highlander: true }]
69
+ @instance.cache_job(*args)
70
+ @instance.cached_jobs.keys.include?("String-to_s").must_equal true
71
+ @instance.cached_jobs["String-to_s"].must_equal args
72
+ end
73
+
74
+ it "understand string keys" do
75
+ args = [String, :to_s, { 'highlander' => true }]
76
+ @instance.cache_job(*args)
77
+ @instance.cached_jobs.keys.include?("String-to_s").must_equal true
78
+ @instance.cached_jobs["String-to_s"].must_equal args
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+ end
@@ -103,6 +103,29 @@ class PerformerTest < MiniTest::Test
103
103
  singleton_mock.verify
104
104
  end
105
105
  end
106
+
107
+ describe 'highlander option' do
108
+
109
+ before { ConeyIsland.flush_jobs; ConeyIsland.cache_jobs }
110
+ after { ConeyIsland.flush_jobs; ConeyIsland.stop_caching_jobs }
111
+
112
+ it "is understood by performers" do
113
+ 5.times { MyHighlander.increment_async }
114
+ assert_equal 1, ConeyIsland.cached_jobs.length
115
+ end
116
+ end
117
+ end
118
+
119
+ class MyHighlander
120
+ include ConeyIsland::Performer
121
+
122
+ set_background_defaults highlander: true
123
+ cattr_reader :counter
124
+ @@counter = 0
125
+
126
+ def self.increment
127
+ @@counter += 1
128
+ end
106
129
  end
107
130
 
108
131
  class MySingleton
@@ -26,6 +26,7 @@ class SubmitterTest < MiniTest::Test
26
26
  @exchange.verify
27
27
  end
28
28
  end
29
+
29
30
  describe "error handling" do
30
31
  it "breaks if klass is not a class or a Module" do
31
32
  error = assert_raises(ConeyIsland::JobArgumentError) do
@@ -8,6 +8,7 @@ require 'minitest/autorun'
8
8
  require 'minitest/pride'
9
9
  require 'request_store'
10
10
  require 'amqp'
11
+ require 'mocha/mini_test'
11
12
 
12
13
  Rails.backtrace_cleaner.remove_silencers!
13
14
  # Load support files
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coney_island
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Draut
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-08-06 00:00:00.000000000 Z
13
+ date: 2016-08-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -128,6 +128,20 @@ dependencies:
128
128
  - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: mocha
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
131
145
  description: An industrial-strength background worker system for rails using RabbitMQ.
132
146
  email:
133
147
  - edraut@gmail.com
@@ -141,10 +155,15 @@ files:
141
155
  - bin/coney_island
142
156
  - lib/coney_island.rb
143
157
  - lib/coney_island/coney_island_adapter.rb
158
+ - lib/coney_island/configuration_error.rb
144
159
  - lib/coney_island/job.rb
145
160
  - lib/coney_island/job_argument_error.rb
161
+ - lib/coney_island/jobs_cache.rb
146
162
  - lib/coney_island/notifiers/airbrake_notifier.rb
163
+ - lib/coney_island/notifiers/base_notifier.rb
164
+ - lib/coney_island/notifiers/bugsnag_notifier.rb
147
165
  - lib/coney_island/notifiers/honeybadger_notifier.rb
166
+ - lib/coney_island/notifiers/null_notifier.rb
148
167
  - lib/coney_island/performer.rb
149
168
  - lib/coney_island/submitter.rb
150
169
  - lib/coney_island/version.rb
@@ -187,6 +206,7 @@ files:
187
206
  - test/dummy/public/500.html
188
207
  - test/dummy/public/favicon.ico
189
208
  - test/job_test.rb
209
+ - test/jobs_cache_test.rb
190
210
  - test/performer_test.rb
191
211
  - test/submitter_test.rb
192
212
  - test/test_helper.rb
@@ -211,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
231
  version: '0'
212
232
  requirements: []
213
233
  rubyforge_project:
214
- rubygems_version: 2.5.1
234
+ rubygems_version: 2.4.5.1
215
235
  signing_key:
216
236
  specification_version: 4
217
237
  summary: Want guaranteed delivery between your queue and your workers using ACKs?
@@ -219,43 +239,44 @@ summary: Want guaranteed delivery between your queue and your workers using ACKs
219
239
  offer and you must have a ticket to ride at Coney Island.
220
240
  test_files:
221
241
  - test/coney_island_test.rb
222
- - test/dummy/app/assets/javascripts/application.js
223
242
  - test/dummy/app/assets/stylesheets/application.css
224
- - test/dummy/app/controllers/application_controller.rb
243
+ - test/dummy/app/assets/javascripts/application.js
225
244
  - test/dummy/app/helpers/application_helper.rb
226
245
  - test/dummy/app/views/layouts/application.html.erb
227
- - test/dummy/bin/bundle
228
- - test/dummy/bin/rails
229
- - test/dummy/bin/rake
230
- - test/dummy/config/application.rb
246
+ - test/dummy/app/controllers/application_controller.rb
247
+ - test/dummy/config.ru
248
+ - test/dummy/log/test.log
249
+ - test/dummy/Rakefile
250
+ - test/dummy/config/locales/en.yml
231
251
  - test/dummy/config/boot.rb
232
252
  - test/dummy/config/database.yml
233
- - test/dummy/config/environment.rb
234
- - test/dummy/config/environments/development.rb
253
+ - test/dummy/config/application.rb
235
254
  - test/dummy/config/environments/production.rb
236
255
  - test/dummy/config/environments/test.rb
256
+ - test/dummy/config/environments/development.rb
257
+ - test/dummy/config/environment.rb
258
+ - test/dummy/config/routes.rb
237
259
  - test/dummy/config/initializers/assets.rb
238
- - test/dummy/config/initializers/backtrace_silencers.rb
239
- - test/dummy/config/initializers/cookies_serializer.rb
260
+ - test/dummy/config/initializers/wrap_parameters.rb
240
261
  - test/dummy/config/initializers/filter_parameter_logging.rb
241
262
  - test/dummy/config/initializers/inflections.rb
242
- - test/dummy/config/initializers/mime_types.rb
243
263
  - test/dummy/config/initializers/session_store.rb
244
- - test/dummy/config/initializers/wrap_parameters.rb
245
- - test/dummy/config/locales/en.yml
246
- - test/dummy/config/routes.rb
264
+ - test/dummy/config/initializers/backtrace_silencers.rb
265
+ - test/dummy/config/initializers/cookies_serializer.rb
266
+ - test/dummy/config/initializers/mime_types.rb
247
267
  - test/dummy/config/secrets.yml
248
- - test/dummy/config.ru
249
- - test/dummy/db/test.sqlite3
250
- - test/dummy/log/test.log
251
268
  - test/dummy/public/404.html
252
269
  - test/dummy/public/422.html
253
270
  - test/dummy/public/500.html
254
271
  - test/dummy/public/favicon.ico
255
- - test/dummy/Rakefile
272
+ - test/dummy/db/test.sqlite3
256
273
  - test/dummy/README.rdoc
257
- - test/job_test.rb
258
- - test/performer_test.rb
274
+ - test/dummy/bin/bundle
275
+ - test/dummy/bin/rake
276
+ - test/dummy/bin/rails
259
277
  - test/submitter_test.rb
260
- - test/test_helper.rb
261
278
  - test/worker_test.rb
279
+ - test/jobs_cache_test.rb
280
+ - test/performer_test.rb
281
+ - test/job_test.rb
282
+ - test/test_helper.rb