asynchronic 3.0.2 → 4.0.2
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 +4 -4
- data/.travis.yml +1 -0
- data/README.md +1 -1
- data/asynchronic.gemspec +1 -1
- data/lib/asynchronic/data_store/in_memory.rb +21 -16
- data/lib/asynchronic/data_store/key.rb +3 -3
- data/lib/asynchronic/data_store/lazy_value.rb +5 -3
- data/lib/asynchronic/data_store/redis.rb +22 -14
- data/lib/asynchronic/data_store/scoped_store.rb +18 -19
- data/lib/asynchronic/environment.rb +3 -3
- data/lib/asynchronic/error.rb +2 -3
- data/lib/asynchronic/garbage_collector.rb +2 -1
- data/lib/asynchronic/job.rb +12 -12
- data/lib/asynchronic/notifier/broadcaster.rb +8 -4
- data/lib/asynchronic/process.rb +35 -32
- data/lib/asynchronic/queue_engine/in_memory.rb +17 -11
- data/lib/asynchronic/queue_engine/ost.rb +7 -5
- data/lib/asynchronic/queue_engine/synchronic.rb +21 -9
- data/lib/asynchronic/version.rb +1 -1
- data/lib/asynchronic/worker.rb +7 -10
- data/lib/asynchronic.rb +8 -0
- data/spec/data_store/data_store_examples.rb +17 -9
- data/spec/data_store/in_memory_spec.rb +0 -2
- data/spec/data_store/key_spec.rb +1 -1
- data/spec/data_store/lazy_value_examples.rb +7 -5
- data/spec/data_store/redis_spec.rb +4 -10
- data/spec/expectations.rb +2 -2
- data/spec/facade_spec.rb +3 -3
- data/spec/jobs.rb +10 -10
- data/spec/minitest_helper.rb +5 -12
- data/spec/process/life_cycle_examples.rb +24 -22
- data/spec/process/life_cycle_in_memory_spec.rb +0 -1
- data/spec/process/life_cycle_redis_spec.rb +0 -1
- data/spec/queue_engine/in_memory_spec.rb +1 -3
- data/spec/queue_engine/ost_spec.rb +1 -7
- data/spec/queue_engine/queue_engine_examples.rb +17 -9
- data/spec/queue_engine/synchronic_spec.rb +1 -1
- data/spec/worker/in_memory_spec.rb +1 -2
- data/spec/worker/redis_spec.rb +0 -6
- data/spec/worker/worker_examples.rb +6 -4
- metadata +9 -3
@@ -5,7 +5,7 @@ module Asynchronic
|
|
5
5
|
attr_reader :stubs
|
6
6
|
|
7
7
|
def initialize(options={})
|
8
|
-
@
|
8
|
+
@options = options
|
9
9
|
@stubs = {}
|
10
10
|
end
|
11
11
|
|
@@ -14,7 +14,7 @@ module Asynchronic
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def environment
|
17
|
-
@environment ||= Asynchronic.environment
|
17
|
+
@environment ||= options.fetch(:environment, Asynchronic.environment)
|
18
18
|
end
|
19
19
|
|
20
20
|
def [](name)
|
@@ -22,7 +22,7 @@ module Asynchronic
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def stub(job, &block)
|
25
|
-
|
25
|
+
stubs[job] = block
|
26
26
|
end
|
27
27
|
|
28
28
|
def asynchronic?
|
@@ -33,6 +33,10 @@ module Asynchronic
|
|
33
33
|
[Asynchronic.connection_name]
|
34
34
|
end
|
35
35
|
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :options
|
39
|
+
|
36
40
|
|
37
41
|
class Queue
|
38
42
|
|
@@ -41,37 +45,45 @@ module Asynchronic
|
|
41
45
|
end
|
42
46
|
|
43
47
|
def push(message)
|
44
|
-
process =
|
48
|
+
process = engine.environment.load_process(message)
|
45
49
|
|
46
|
-
if
|
50
|
+
if engine.stubs[process.type]
|
47
51
|
job = process.job
|
48
|
-
block =
|
52
|
+
block = engine.stubs[process.type]
|
49
53
|
process.define_singleton_method :job do
|
50
|
-
MockJob.new job, process,
|
54
|
+
MockJob.new job, process, block
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
54
58
|
process.execute
|
55
59
|
end
|
56
60
|
|
61
|
+
private
|
62
|
+
|
63
|
+
attr_reader :engine
|
64
|
+
|
57
65
|
end
|
58
66
|
|
59
67
|
|
60
68
|
class MockJob < TransparentProxy
|
61
69
|
|
62
|
-
def initialize(job, process,
|
70
|
+
def initialize(job, process, block)
|
63
71
|
super job
|
64
72
|
@process = process
|
65
73
|
@block = block
|
66
74
|
end
|
67
75
|
|
68
76
|
def call
|
69
|
-
|
77
|
+
block.call process
|
70
78
|
end
|
71
79
|
|
72
80
|
def before_finalize
|
73
81
|
end
|
74
82
|
|
83
|
+
private
|
84
|
+
|
85
|
+
attr_reader :process, :block
|
86
|
+
|
75
87
|
end
|
76
88
|
|
77
89
|
end
|
data/lib/asynchronic/version.rb
CHANGED
data/lib/asynchronic/worker.rb
CHANGED
@@ -1,24 +1,21 @@
|
|
1
1
|
class Asynchronic::Worker
|
2
2
|
|
3
|
-
attr_reader :queue
|
4
|
-
attr_reader :queue_name
|
5
|
-
attr_reader :env
|
6
|
-
attr_reader :listener
|
3
|
+
attr_reader :queue, :queue_name, :environment, :listener
|
7
4
|
|
8
|
-
def initialize(queue_name,
|
5
|
+
def initialize(queue_name, environment)
|
9
6
|
@queue_name = queue_name
|
10
|
-
@queue =
|
11
|
-
@
|
12
|
-
@listener =
|
7
|
+
@queue = environment.queue_engine[queue_name]
|
8
|
+
@environment = environment
|
9
|
+
@listener = environment.queue_engine.listener
|
13
10
|
end
|
14
11
|
|
15
12
|
def start
|
16
13
|
Asynchronic.logger.info('Asynchronic') { "Starting worker of #{queue_name} (#{Process.pid})" }
|
17
14
|
|
18
15
|
Signal.trap('QUIT') { stop }
|
19
|
-
|
16
|
+
|
20
17
|
listener.listen(queue) do |pid|
|
21
|
-
|
18
|
+
environment.load_process(pid).execute
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
data/lib/asynchronic.rb
CHANGED
@@ -23,6 +23,8 @@ module Asynchronic
|
|
23
23
|
attr_config :logger, Logger.new($stdout)
|
24
24
|
attr_config :retry_timeout, 30
|
25
25
|
attr_config :garbage_collector_timeout, 30
|
26
|
+
attr_config :redis_client, Redic
|
27
|
+
attr_config :redis_settings, 'redis://localhost:6379'
|
26
28
|
attr_config :redis_data_store_sync_timeout, 0.01
|
27
29
|
attr_config :keep_alive_timeout, 1
|
28
30
|
attr_config :connection_name, "HOST=#{Socket.gethostname},PID=#{::Process.pid},UUID=#{SecureRandom.uuid}"
|
@@ -43,6 +45,12 @@ module Asynchronic
|
|
43
45
|
@garbage_collector ||= GarbageCollector.new environment, garbage_collector_timeout
|
44
46
|
end
|
45
47
|
|
48
|
+
def self.establish_redis_connection(options={})
|
49
|
+
redis_client = options.fetch(:redis_client, Asynchronic.redis_client)
|
50
|
+
redis_settings = options.fetch(:redis_settings, Asynchronic.redis_settings)
|
51
|
+
redis_client.new redis_settings
|
52
|
+
end
|
53
|
+
|
46
54
|
def self.retry_execution(klass, message)
|
47
55
|
begin
|
48
56
|
result = yield
|
@@ -1,5 +1,11 @@
|
|
1
1
|
module DataStoreExamples
|
2
|
-
|
2
|
+
|
3
|
+
extend Minitest::Spec::DSL
|
4
|
+
|
5
|
+
after do
|
6
|
+
data_store.clear
|
7
|
+
end
|
8
|
+
|
3
9
|
it 'Get/Set value' do
|
4
10
|
data_store[:key] = 123
|
5
11
|
data_store[:key].must_equal 123
|
@@ -32,8 +38,8 @@ module DataStoreExamples
|
|
32
38
|
data_store.delete_cascade Asynchronic::DataStore::Key[:key_1]
|
33
39
|
|
34
40
|
data_store.keys.sort.must_equal [
|
35
|
-
Asynchronic::DataStore::Key[:key_2],
|
36
|
-
Asynchronic::DataStore::Key[:key_2][:key_2_1],
|
41
|
+
Asynchronic::DataStore::Key[:key_2],
|
42
|
+
Asynchronic::DataStore::Key[:key_2][:key_2_1],
|
37
43
|
Asynchronic::DataStore::Key[:key_2][:key_2_2]
|
38
44
|
]
|
39
45
|
end
|
@@ -110,18 +116,20 @@ module DataStoreExamples
|
|
110
116
|
|
111
117
|
it 'Synchronization' do
|
112
118
|
sum = 0
|
113
|
-
|
119
|
+
|
120
|
+
threads = 10.times.map do
|
114
121
|
Thread.new do
|
115
|
-
data_store.synchronize('
|
122
|
+
data_store.synchronize('lock_key') do
|
116
123
|
temp = sum
|
117
|
-
sleep 0
|
124
|
+
sleep 0.01
|
118
125
|
sum = temp + 1
|
119
126
|
end
|
120
127
|
end
|
121
128
|
end
|
129
|
+
|
122
130
|
threads.each(&:join)
|
123
|
-
|
124
|
-
sum.must_equal
|
131
|
+
|
132
|
+
sum.must_equal threads.count
|
125
133
|
end
|
126
|
-
|
134
|
+
|
127
135
|
end
|
data/spec/data_store/key_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module LazyValueExamples
|
2
2
|
|
3
|
+
extend Minitest::Spec::DSL
|
4
|
+
|
3
5
|
def lazy_value(key)
|
4
6
|
Asynchronic::DataStore::LazyValue.new data_store, key
|
5
7
|
end
|
@@ -7,25 +9,25 @@ module LazyValueExamples
|
|
7
9
|
it 'Get' do
|
8
10
|
value = lazy_value :key
|
9
11
|
value.must_be_nil
|
10
|
-
|
11
|
-
data_store[:key] =
|
12
|
+
|
13
|
+
data_store[:key] = 1
|
12
14
|
value.must_equal 1
|
13
15
|
end
|
14
16
|
|
15
17
|
it 'Reload' do
|
16
18
|
value = lazy_value :key
|
17
19
|
|
18
|
-
data_store[:key] =
|
20
|
+
data_store[:key] = 1
|
19
21
|
value.must_equal 1
|
20
22
|
|
21
|
-
data_store[:key] =
|
23
|
+
data_store[:key] = 2
|
22
24
|
value.must_equal 1
|
23
25
|
value.reload.must_equal 2
|
24
26
|
end
|
25
27
|
|
26
28
|
it 'Transparent proxy' do
|
27
29
|
value = lazy_value :key
|
28
|
-
data_store[:key] =
|
30
|
+
data_store[:key] = 1
|
29
31
|
value.must_equal 1
|
30
32
|
end
|
31
33
|
|
@@ -1,17 +1,15 @@
|
|
1
1
|
require 'minitest_helper'
|
2
|
-
require_relative './data_store_examples'
|
3
|
-
require_relative './lazy_value_examples'
|
4
2
|
|
5
3
|
describe Asynchronic::DataStore::Redis do
|
6
4
|
|
7
5
|
let(:data_store) { Asynchronic::DataStore::Redis.new :asynchronic_test }
|
8
6
|
|
9
|
-
after do
|
10
|
-
data_store.clear
|
11
|
-
end
|
12
|
-
|
13
7
|
include DataStoreExamples
|
14
8
|
|
9
|
+
describe 'LazyValue' do
|
10
|
+
include LazyValueExamples
|
11
|
+
end
|
12
|
+
|
15
13
|
it 'Safe deserialization' do
|
16
14
|
SampleClass = Class.new
|
17
15
|
|
@@ -24,8 +22,4 @@ describe Asynchronic::DataStore::Redis do
|
|
24
22
|
data_store[:instance].must_be_instance_of String
|
25
23
|
end
|
26
24
|
|
27
|
-
describe 'LazyValue' do
|
28
|
-
include LazyValueExamples
|
29
|
-
end
|
30
|
-
|
31
25
|
end
|
data/spec/expectations.rb
CHANGED
@@ -15,10 +15,10 @@ module MiniTest::Assertions
|
|
15
15
|
def assert_be_initialized(process)
|
16
16
|
process.must_be :pending?
|
17
17
|
process.wont_be :finalized?
|
18
|
-
|
18
|
+
|
19
19
|
process.processes.must_be_empty
|
20
20
|
process.error.must_be_nil
|
21
|
-
|
21
|
+
|
22
22
|
process.created_at.must_be_instance_of Time
|
23
23
|
process.queued_at.must_be_nil
|
24
24
|
process.started_at.must_be_nil
|
data/spec/facade_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Asynchronic, 'Facade' do
|
|
6
6
|
Asynchronic.environment.data_store.clear
|
7
7
|
Asynchronic.environment.queue_engine.clear
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it 'Default queue' do
|
11
11
|
Asynchronic.default_queue.must_equal :asynchronic_test
|
12
12
|
end
|
@@ -40,7 +40,7 @@ describe Asynchronic, 'Facade' do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'List processes' do
|
43
|
-
ids = 3.times.map do
|
43
|
+
ids = 3.times.map do
|
44
44
|
process = Asynchronic.environment.create_process SequentialJob
|
45
45
|
process.id
|
46
46
|
end
|
@@ -51,7 +51,7 @@ describe Asynchronic, 'Facade' do
|
|
51
51
|
|
52
52
|
it 'Enqueue' do
|
53
53
|
id = BasicJob.enqueue input: 100
|
54
|
-
|
54
|
+
|
55
55
|
Asynchronic.environment.tap do |env|
|
56
56
|
process = env.load_process id
|
57
57
|
process.type.must_equal BasicJob
|
data/spec/jobs.rb
CHANGED
@@ -9,8 +9,8 @@ class SequentialJob < Asynchronic::Job
|
|
9
9
|
|
10
10
|
def call
|
11
11
|
async Step1, input: params[:input]
|
12
|
-
|
13
|
-
async Step2, dependency: Step1,
|
12
|
+
|
13
|
+
async Step2, dependency: Step1,
|
14
14
|
input: params[:input]
|
15
15
|
|
16
16
|
nil
|
@@ -32,7 +32,7 @@ end
|
|
32
32
|
|
33
33
|
|
34
34
|
class GraphJob < Asynchronic::Job
|
35
|
-
|
35
|
+
|
36
36
|
def call
|
37
37
|
async Sum, input: params[:input]
|
38
38
|
|
@@ -113,13 +113,13 @@ class AliasJob < Asynchronic::Job
|
|
113
113
|
def call
|
114
114
|
async Write, alias: :word_1,
|
115
115
|
text: 'Take'
|
116
|
-
|
117
|
-
async Write, alias: :word_2,
|
118
|
-
text: 'it',
|
116
|
+
|
117
|
+
async Write, alias: :word_2,
|
118
|
+
text: 'it',
|
119
119
|
prefix: result(:word_1)
|
120
|
-
|
121
|
-
async Write, alias: :word_3,
|
122
|
-
text: 'easy',
|
120
|
+
|
121
|
+
async Write, alias: :word_3,
|
122
|
+
text: 'easy',
|
123
123
|
prefix: result(:word_2)
|
124
124
|
|
125
125
|
result :word_3
|
@@ -402,4 +402,4 @@ class BeforeFinalizeExceptionOnAbortedJob < Asynchronic::Job
|
|
402
402
|
def before_finalize
|
403
403
|
raise 'Before finalize error'
|
404
404
|
end
|
405
|
-
end
|
405
|
+
end
|
data/spec/minitest_helper.rb
CHANGED
@@ -9,9 +9,11 @@ require 'expectations'
|
|
9
9
|
require 'timeout'
|
10
10
|
require 'pry-nav'
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
require_relative 'data_store/data_store_examples'
|
13
|
+
require_relative 'data_store/lazy_value_examples'
|
14
|
+
require_relative 'process/life_cycle_examples'
|
15
|
+
require_relative 'queue_engine/queue_engine_examples'
|
16
|
+
require_relative 'worker/worker_examples'
|
15
17
|
|
16
18
|
Asynchronic.logger.level = Logger::FATAL
|
17
19
|
|
@@ -20,13 +22,4 @@ class Minitest::Spec
|
|
20
22
|
Asynchronic.restore_default_configuration
|
21
23
|
Asynchronic.default_queue = :asynchronic_test
|
22
24
|
end
|
23
|
-
end
|
24
|
-
|
25
|
-
module Asynchronic::DataStore::Helper
|
26
|
-
def dump
|
27
|
-
puts 'DataStore:'
|
28
|
-
each do |k,v|
|
29
|
-
puts "#{k}: #{v}"
|
30
|
-
end
|
31
|
-
end
|
32
25
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module LifeCycleExamples
|
2
|
-
|
2
|
+
|
3
|
+
extend Minitest::Spec::DSL
|
4
|
+
|
3
5
|
let(:env) { Asynchronic::Environment.new queue_engine, data_store, notifier }
|
4
6
|
|
5
7
|
let(:queue) { env.default_queue }
|
@@ -29,7 +31,7 @@ module LifeCycleExamples
|
|
29
31
|
|
30
32
|
process.must_have_connection_name
|
31
33
|
process.wont_be :dead?
|
32
|
-
|
34
|
+
|
33
35
|
process.send(:connected?).must_be_true
|
34
36
|
|
35
37
|
env.queue_engine.stub(:active_connections, ->() { raise 'Forced error' }) do
|
@@ -138,7 +140,7 @@ module LifeCycleExamples
|
|
138
140
|
process[GraphJob::Total].must_be_pending
|
139
141
|
process[GraphJob::Total].must_have_params '10%' => nil, '20%' => nil
|
140
142
|
queue.must_enqueued process[GraphJob::Sum]
|
141
|
-
|
143
|
+
|
142
144
|
execute queue
|
143
145
|
|
144
146
|
process.must_be_waiting
|
@@ -294,7 +296,7 @@ module LifeCycleExamples
|
|
294
296
|
process[:word_3].result.must_equal 'Take it easy'
|
295
297
|
queue.must_be_empty
|
296
298
|
end
|
297
|
-
|
299
|
+
|
298
300
|
it 'Custom queue' do
|
299
301
|
process = create CustomQueueJob, input: 'hello'
|
300
302
|
|
@@ -308,7 +310,7 @@ module LifeCycleExamples
|
|
308
310
|
|
309
311
|
process.must_be_queued
|
310
312
|
process.processes.must_be_empty
|
311
|
-
|
313
|
+
|
312
314
|
env.queue(:queue_1).must_enqueued process
|
313
315
|
env.queue(:queue_2).must_be_empty
|
314
316
|
env.queue(:queue_3).must_be_empty
|
@@ -318,7 +320,7 @@ module LifeCycleExamples
|
|
318
320
|
process.must_be_waiting
|
319
321
|
process[CustomQueueJob::Reverse].must_be_queued
|
320
322
|
process[CustomQueueJob::Reverse].must_have_params input: 'hello'
|
321
|
-
|
323
|
+
|
322
324
|
env.queue(:queue_1).must_be_empty
|
323
325
|
env.queue(:queue_2).must_enqueued process[CustomQueueJob::Reverse]
|
324
326
|
env.queue(:queue_3).must_be_empty
|
@@ -329,7 +331,7 @@ module LifeCycleExamples
|
|
329
331
|
process.result.must_equal 'olleh'
|
330
332
|
process[CustomQueueJob::Reverse].must_be_completed
|
331
333
|
process[CustomQueueJob::Reverse].result.must_equal 'olleh'
|
332
|
-
|
334
|
+
|
333
335
|
env.queue(:queue_1).must_be_empty
|
334
336
|
env.queue(:queue_2).must_be_empty
|
335
337
|
env.queue(:queue_3).must_be_empty
|
@@ -485,7 +487,7 @@ module LifeCycleExamples
|
|
485
487
|
|
486
488
|
it 'Data' do
|
487
489
|
process = create DataJob, input: 1
|
488
|
-
|
490
|
+
|
489
491
|
process.enqueue
|
490
492
|
execute queue
|
491
493
|
|
@@ -497,7 +499,7 @@ module LifeCycleExamples
|
|
497
499
|
it 'Nested job with error in child' do
|
498
500
|
process = create NestedJobWithErrorInChildJob
|
499
501
|
|
500
|
-
process.enqueue
|
502
|
+
process.enqueue
|
501
503
|
|
502
504
|
Timeout.timeout(1) do
|
503
505
|
until process.status == :aborted
|
@@ -511,17 +513,17 @@ module LifeCycleExamples
|
|
511
513
|
it 'Nested job with error in parent' do
|
512
514
|
process = create NestedJobWithErrorInParentJob
|
513
515
|
|
514
|
-
process.enqueue
|
516
|
+
process.enqueue
|
515
517
|
|
516
518
|
execute queue
|
517
|
-
|
519
|
+
|
518
520
|
process.real_error.must_equal "Error in parent"
|
519
521
|
end
|
520
522
|
|
521
523
|
it 'Abort queued After error' do
|
522
524
|
process = create AbortQueuedAfterErrorJob
|
523
525
|
|
524
|
-
process.enqueue
|
526
|
+
process.enqueue
|
525
527
|
|
526
528
|
execute queue
|
527
529
|
|
@@ -602,27 +604,27 @@ module LifeCycleExamples
|
|
602
604
|
|
603
605
|
execute queue
|
604
606
|
|
605
|
-
process.full_status.must_equal 'NestedJob' => :waiting,
|
607
|
+
process.full_status.must_equal 'NestedJob' => :waiting,
|
606
608
|
'NestedJob::Level1' => :queued
|
607
609
|
|
608
610
|
execute queue
|
609
611
|
|
610
|
-
process.full_status.must_equal 'NestedJob' => :waiting,
|
611
|
-
'NestedJob::Level1' => :waiting,
|
612
|
+
process.full_status.must_equal 'NestedJob' => :waiting,
|
613
|
+
'NestedJob::Level1' => :waiting,
|
612
614
|
'NestedJob::Level1::Level2' => :queued
|
613
615
|
|
614
616
|
process.cancel!
|
615
617
|
|
616
618
|
process.real_error.must_equal Asynchronic::Process::CANCELED_ERROR_MESSAGE
|
617
619
|
|
618
|
-
process.full_status.must_equal 'NestedJob' => :aborted,
|
619
|
-
'NestedJob::Level1' => :waiting,
|
620
|
+
process.full_status.must_equal 'NestedJob' => :aborted,
|
621
|
+
'NestedJob::Level1' => :waiting,
|
620
622
|
'NestedJob::Level1::Level2' => :queued
|
621
623
|
|
622
624
|
execute queue
|
623
625
|
|
624
|
-
process.full_status.must_equal 'NestedJob' => :aborted,
|
625
|
-
'NestedJob::Level1' => :aborted,
|
626
|
+
process.full_status.must_equal 'NestedJob' => :aborted,
|
627
|
+
'NestedJob::Level1' => :aborted,
|
626
628
|
'NestedJob::Level1::Level2' => :aborted
|
627
629
|
end
|
628
630
|
|
@@ -650,7 +652,7 @@ module LifeCycleExamples
|
|
650
652
|
process_1 = create AliasJob
|
651
653
|
process_1.enqueue
|
652
654
|
4.times { execute queue }
|
653
|
-
|
655
|
+
|
654
656
|
process_2 = create AliasJob
|
655
657
|
process_2.enqueue
|
656
658
|
execute queue
|
@@ -670,7 +672,7 @@ module LifeCycleExamples
|
|
670
672
|
data_store.keys.select { |k| k.start_with? pid_3 }.count.must_equal 7
|
671
673
|
|
672
674
|
gc = Asynchronic::GarbageCollector.new env, 0.001
|
673
|
-
|
675
|
+
|
674
676
|
gc.add_condition('Finalized', &:finalized?)
|
675
677
|
gc.add_condition('Waiting', &:waiting?)
|
676
678
|
gc.add_condition('Exception') { raise 'Invalid condition' }
|
@@ -678,7 +680,7 @@ module LifeCycleExamples
|
|
678
680
|
gc.conditions_names.must_equal ['Finalized', 'Waiting', 'Exception']
|
679
681
|
|
680
682
|
gc.remove_condition 'Waiting'
|
681
|
-
|
683
|
+
|
682
684
|
gc.conditions_names.must_equal ['Finalized', 'Exception']
|
683
685
|
|
684
686
|
Thread.new do
|
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'minitest_helper'
|
2
|
-
require_relative './queue_engine_examples'
|
3
2
|
|
4
3
|
describe Asynchronic::QueueEngine::InMemory do
|
5
4
|
|
6
5
|
let(:engine) { Asynchronic::QueueEngine::InMemory.new }
|
7
|
-
let(:listener) { Asynchronic::QueueEngine::InMemory::Listener.new }
|
8
6
|
|
9
7
|
include QueueEngineExamples
|
10
|
-
|
8
|
+
|
11
9
|
end
|
@@ -1,19 +1,13 @@
|
|
1
1
|
require 'minitest_helper'
|
2
|
-
require_relative './queue_engine_examples'
|
3
2
|
|
4
3
|
describe Asynchronic::QueueEngine::Ost do
|
5
4
|
|
6
5
|
let(:engine) { Asynchronic::QueueEngine::Ost.new }
|
7
|
-
let(:listener) { Asynchronic::QueueEngine::Ost::Listener.new }
|
8
6
|
|
9
|
-
before do
|
10
|
-
engine.clear
|
11
|
-
end
|
12
|
-
|
13
7
|
include QueueEngineExamples
|
14
8
|
|
15
9
|
it 'Engine and queues use same redis connection' do
|
16
10
|
engine.redis.must_equal queue.redis
|
17
11
|
end
|
18
|
-
|
12
|
+
|
19
13
|
end
|
@@ -1,26 +1,34 @@
|
|
1
1
|
module QueueEngineExamples
|
2
|
-
|
2
|
+
|
3
|
+
extend Minitest::Spec::DSL
|
4
|
+
|
3
5
|
let(:queue) { engine[:test_queue] }
|
4
6
|
|
7
|
+
let(:listener) { engine.listener }
|
8
|
+
|
9
|
+
after do
|
10
|
+
engine.clear
|
11
|
+
end
|
12
|
+
|
5
13
|
it 'Engine' do
|
6
|
-
engine.
|
7
|
-
|
14
|
+
engine.queue_names.must_be_empty
|
15
|
+
|
8
16
|
queue = engine[:test_engine]
|
9
17
|
queue.must_be_instance_of engine.class.const_get(:Queue)
|
10
|
-
engine.
|
11
|
-
|
18
|
+
engine.queue_names.must_equal [:test_engine]
|
19
|
+
|
12
20
|
engine[:test_engine].must_equal queue
|
13
|
-
|
21
|
+
|
14
22
|
engine.clear
|
15
|
-
engine.
|
23
|
+
engine.queue_names.must_be_empty
|
16
24
|
end
|
17
25
|
|
18
26
|
it 'Queue (push/pop)' do
|
19
27
|
queue.must_be_empty
|
20
|
-
|
28
|
+
|
21
29
|
queue.push 'msg_1'
|
22
30
|
queue.push 'msg_2'
|
23
|
-
|
31
|
+
|
24
32
|
queue.size.must_equal 2
|
25
33
|
queue.to_a.must_equal %w(msg_1 msg_2)
|
26
34
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'minitest_helper'
|
2
|
-
require_relative './worker_examples'
|
3
2
|
|
4
3
|
describe Asynchronic::Worker, 'InMemory' do
|
5
4
|
|
@@ -8,5 +7,5 @@ describe Asynchronic::Worker, 'InMemory' do
|
|
8
7
|
let(:notifier) { Asynchronic::Notifier::InMemory.new }
|
9
8
|
|
10
9
|
include WorkerExamples
|
11
|
-
|
10
|
+
|
12
11
|
end
|