canvas_sync 0.17.3.beta3 → 0.17.6.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -227,6 +227,34 @@ RSpec.describe CanvasSync::JobBatches::Batch do
227
227
  end
228
228
  end
229
229
 
230
+ it 'delays triggering callbacks if keep_open is set' do
231
+ ActiveJob::Base.queue_adapter = :sidekiq
232
+ CanvasSync::JobBatches::Batch::Callback.worker_class = CanvasSync::JobBatches::Sidekiq::SidekiqCallbackWorker
233
+
234
+ callback_instance = double('SampleCallback')
235
+ expect(SampleCallback).to receive(:new).at_least(1).times.and_return(callback_instance)
236
+ expect(callback_instance).not_to receive(:on_complete)
237
+ expect(callback_instance).not_to receive(:on_success)
238
+
239
+ batch.on(:complete, SampleCallback)
240
+ batch.on(:success, SampleCallback)
241
+ batch.keep_open!
242
+
243
+ Sidekiq::Testing.inline! do
244
+ CanvasSync::JobBatches::Batch.process_failed_job(bid, jid)
245
+ CanvasSync::JobBatches::Batch.process_successful_job(bid, jid)
246
+ end
247
+
248
+ RSpec::Mocks.space.proxy_for(callback_instance).reset
249
+
250
+ expect(callback_instance).to receive(:on_complete)
251
+ expect(callback_instance).to receive(:on_success)
252
+
253
+ Sidekiq::Testing.inline! do
254
+ batch.let_close!
255
+ end
256
+ end
257
+
230
258
  it 'triggers callbacks as expected' do
231
259
  ActiveJob::Base.queue_adapter = :sidekiq
232
260
  CanvasSync::JobBatches::Batch.redis { |r| r.hset("BID-#{bid}", 'pending', 0) }
@@ -272,7 +300,6 @@ RSpec.describe CanvasSync::JobBatches::Batch do
272
300
  end
273
301
 
274
302
  describe '#increment_job_queue' do
275
- let(:bid) { 'BID' }
276
303
  let(:batch) { CanvasSync::JobBatches::Batch.new }
277
304
 
278
305
  it 'increments pending' do
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CanvasSync::JobBatches::ContextHash do
4
+
5
+ class ContextedJob < BatchTestJobBase
6
+ def perform
7
+ was_performed(batch_context.flatten)
8
+ end
9
+
10
+ def was_performed(*args); end
11
+
12
+ def self.callback_perform(*args)
13
+ perform_later
14
+ end
15
+ end
16
+
17
+ it "works with first-level jobs" do
18
+ ActiveJob::Base.queue_adapter = :sidekiq
19
+ b = CanvasSync::JobBatches::Batch.new
20
+ b.context = { hello: 'world' }
21
+ expect_any_instance_of(ContextedJob).to receive(:was_performed).with({ 'hello' => 'world' })
22
+ b.jobs do
23
+ ContextedJob.perform_later
24
+ end
25
+ Sidekiq::Worker.drain_all
26
+ end
27
+
28
+ it "works with nested-batch jobs" do
29
+ ActiveJob::Base.queue_adapter = :sidekiq
30
+ b = CanvasSync::JobBatches::Batch.new
31
+ b.context = { hello: 'world', foo: 'bar' }
32
+ expect_any_instance_of(ContextedJob).to receive(:was_performed).with({ 'hello' => 'world', 'foo' => 'baz', 'some' => 'other' })
33
+ b.jobs do
34
+ b2 = CanvasSync::JobBatches::Batch.new
35
+ b2.context = { some: 'other', foo: 'baz' }
36
+ b2.jobs do
37
+ ContextedJob.perform_later
38
+ end
39
+ end
40
+ Sidekiq::Worker.drain_all
41
+ end
42
+
43
+ it 'works with a callback batch' do
44
+ ActiveJob::Base.queue_adapter = :sidekiq
45
+ b = CanvasSync::JobBatches::Batch.new
46
+ b.context = { hello: 'world' }
47
+ b.on(:success, "ContextedJob.callback_perform")
48
+ expect_any_instance_of(ContextedJob).to receive(:was_performed).with({ 'hello' => 'world' })
49
+ b.jobs do
50
+ BatchTestJobBase.perform_later
51
+ end
52
+ Sidekiq::Worker.drain_all
53
+ end
54
+ end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe CanvasSync::JobBatches::Batch::Status do
4
- let(:bid) { 'BID' }
5
- let(:batch) { CanvasSync::JobBatches::Batch.new(bid) }
4
+ let(:batch) { CanvasSync::JobBatches::Batch.new() }
5
+ let(:bid) { batch.bid }
6
6
  subject { described_class.new(bid) }
7
7
 
8
8
  describe '#join' do
@@ -51,7 +51,7 @@ RSpec.describe CanvasSync::JobBatches::Batch::Status do
51
51
  end
52
52
 
53
53
  context 'when with error' do
54
- before { CanvasSync::JobBatches::Batch.process_failed_job(bid, 'jid123') }
54
+ before { batch.jobs{}; CanvasSync::JobBatches::Batch.process_failed_job(bid, 'jid123') }
55
55
 
56
56
  it 'returns array with failed jids' do
57
57
  expect(subject.failure_info).to eq(['jid123'])
@@ -15,17 +15,13 @@ require 'pry-nav'
15
15
 
16
16
  require 'sidekiq/testing'
17
17
  Sidekiq::Testing.fake!
18
+ Sidekiq::Testing.server_middleware do |chain|
19
+ chain.add CanvasSync::JobBatches::Sidekiq::ServerMiddleware
20
+ end
18
21
 
19
22
  require 'fakeredis/rspec'
20
23
  Dir[File.dirname(__FILE__) + "/job_batching/support/**/*.rb"].each {|f| require f }
21
24
 
22
- # Fix an issue with fakeredis with Redis >=4.2
23
- class Redis::Connection::Memory
24
- def exists(*keys)
25
- keys.count { |key| data.key?(key) }
26
- end
27
- end
28
-
29
25
  ActiveRecord::Migration.maintain_test_schema!
30
26
 
31
27
  RSpec.configure do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.3.beta3
4
+ version: 0.17.6.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Collings
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-16 00:00:00.000000000 Z
11
+ date: 2020-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -234,20 +234,6 @@ dependencies:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
- - !ruby/object:Gem::Dependency
238
- name: fakeredis
239
- requirement: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - ">="
242
- - !ruby/object:Gem::Version
243
- version: '0'
244
- type: :development
245
- prerelease: false
246
- version_requirements: !ruby/object:Gem::Requirement
247
- requirements:
248
- - - ">="
249
- - !ruby/object:Gem::Version
250
- version: '0'
251
237
  - !ruby/object:Gem::Dependency
252
238
  name: sidekiq
253
239
  requirement: !ruby/object:Gem::Requirement
@@ -436,6 +422,14 @@ files:
436
422
  - lib/canvas_sync/job_batches/redis_model.rb
437
423
  - lib/canvas_sync/job_batches/redis_script.rb
438
424
  - lib/canvas_sync/job_batches/sidekiq.rb
425
+ - lib/canvas_sync/job_batches/sidekiq/web.rb
426
+ - lib/canvas_sync/job_batches/sidekiq/web/helpers.rb
427
+ - lib/canvas_sync/job_batches/sidekiq/web/views/_batches_table.erb
428
+ - lib/canvas_sync/job_batches/sidekiq/web/views/_pagination.erb
429
+ - lib/canvas_sync/job_batches/sidekiq/web/views/batch.erb
430
+ - lib/canvas_sync/job_batches/sidekiq/web/views/batches.erb
431
+ - lib/canvas_sync/job_batches/sidekiq/web/views/pool.erb
432
+ - lib/canvas_sync/job_batches/sidekiq/web/views/pools.erb
439
433
  - lib/canvas_sync/job_batches/status.rb
440
434
  - lib/canvas_sync/jobs/begin_sync_chain_job.rb
441
435
  - lib/canvas_sync/jobs/report_checker.rb
@@ -602,6 +596,7 @@ files:
602
596
  - spec/job_batching/batch_aware_job_spec.rb
603
597
  - spec/job_batching/batch_spec.rb
604
598
  - spec/job_batching/callback_spec.rb
599
+ - spec/job_batching/context_hash_spec.rb
605
600
  - spec/job_batching/flow_spec.rb
606
601
  - spec/job_batching/integration/fail_then_succeed.rb
607
602
  - spec/job_batching/integration/integration.rb
@@ -795,6 +790,7 @@ test_files:
795
790
  - spec/job_batching/batch_aware_job_spec.rb
796
791
  - spec/job_batching/batch_spec.rb
797
792
  - spec/job_batching/callback_spec.rb
793
+ - spec/job_batching/context_hash_spec.rb
798
794
  - spec/job_batching/flow_spec.rb
799
795
  - spec/job_batching/integration/fail_then_succeed.rb
800
796
  - spec/job_batching/integration/integration.rb