spec/process/life_cycle_examples.rb in asynchronic-3.0.3 vs spec/process/life_cycle_examples.rb in asynchronic-4.0.0
- old
+ new
@@ -1,7 +1,9 @@
module LifeCycleExamples
-
+
+ extend Minitest::Spec::DSL
+
let(:env) { Asynchronic::Environment.new queue_engine, data_store, notifier }
let(:queue) { env.default_queue }
after do
@@ -27,11 +29,11 @@
process.execute
process.must_have_connection_name
process.wont_be :dead?
-
+
process.send(:connected?).must_be_true
env.queue_engine.stub(:active_connections, ->() { raise 'Forced error' }) do
process.send(:connected?).must_be_true
end
@@ -136,11 +138,11 @@
process[GraphJob::TwentyPercent].must_be_pending
process[GraphJob::TwentyPercent].must_have_params input: nil
process[GraphJob::Total].must_be_pending
process[GraphJob::Total].must_have_params '10%' => nil, '20%' => nil
queue.must_enqueued process[GraphJob::Sum]
-
+
execute queue
process.must_be_waiting
process[GraphJob::Sum].must_be_completed
process[GraphJob::Sum].result.must_equal 200
@@ -292,11 +294,11 @@
process[:word_2].must_be_completed
process[:word_3].must_be_completed
process[:word_3].result.must_equal 'Take it easy'
queue.must_be_empty
end
-
+
it 'Custom queue' do
process = create CustomQueueJob, input: 'hello'
process.must_have_params input: 'hello'
@@ -306,32 +308,32 @@
process.enqueue
process.must_be_queued
process.processes.must_be_empty
-
+
env.queue(:queue_1).must_enqueued process
env.queue(:queue_2).must_be_empty
env.queue(:queue_3).must_be_empty
execute env.queue(:queue_1)
process.must_be_waiting
process[CustomQueueJob::Reverse].must_be_queued
process[CustomQueueJob::Reverse].must_have_params input: 'hello'
-
+
env.queue(:queue_1).must_be_empty
env.queue(:queue_2).must_enqueued process[CustomQueueJob::Reverse]
env.queue(:queue_3).must_be_empty
execute env.queue(:queue_2)
process.must_be_completed
process.result.must_equal 'olleh'
process[CustomQueueJob::Reverse].must_be_completed
process[CustomQueueJob::Reverse].result.must_equal 'olleh'
-
+
env.queue(:queue_1).must_be_empty
env.queue(:queue_2).must_be_empty
env.queue(:queue_3).must_be_empty
end
@@ -483,11 +485,11 @@
execute queue_engine[:other_queue]
end
it 'Data' do
process = create DataJob, input: 1
-
+
process.enqueue
execute queue
process.must_be_completed
process.result.must_be_nil
@@ -495,11 +497,11 @@
end
it 'Nested job with error in child' do
process = create NestedJobWithErrorInChildJob
- process.enqueue
+ process.enqueue
Timeout.timeout(1) do
until process.status == :aborted
execute queue
end
@@ -509,21 +511,21 @@
end
it 'Nested job with error in parent' do
process = create NestedJobWithErrorInParentJob
- process.enqueue
+ process.enqueue
execute queue
-
+
process.real_error.must_equal "Error in parent"
end
it 'Abort queued After error' do
process = create AbortQueuedAfterErrorJob
- process.enqueue
+ process.enqueue
execute queue
process.full_status.must_equal 'AbortQueuedAfterErrorJob' => :waiting,
'AbortQueuedAfterErrorJob::Child_1' => :queued,
@@ -600,31 +602,31 @@
process.enqueue
execute queue
- process.full_status.must_equal 'NestedJob' => :waiting,
+ process.full_status.must_equal 'NestedJob' => :waiting,
'NestedJob::Level1' => :queued
execute queue
- process.full_status.must_equal 'NestedJob' => :waiting,
- 'NestedJob::Level1' => :waiting,
+ process.full_status.must_equal 'NestedJob' => :waiting,
+ 'NestedJob::Level1' => :waiting,
'NestedJob::Level1::Level2' => :queued
process.cancel!
process.real_error.must_equal Asynchronic::Process::CANCELED_ERROR_MESSAGE
- process.full_status.must_equal 'NestedJob' => :aborted,
- 'NestedJob::Level1' => :waiting,
+ process.full_status.must_equal 'NestedJob' => :aborted,
+ 'NestedJob::Level1' => :waiting,
'NestedJob::Level1::Level2' => :queued
execute queue
- process.full_status.must_equal 'NestedJob' => :aborted,
- 'NestedJob::Level1' => :aborted,
+ process.full_status.must_equal 'NestedJob' => :aborted,
+ 'NestedJob::Level1' => :aborted,
'NestedJob::Level1::Level2' => :aborted
end
it 'Remove process' do
process_1 = create AliasJob
@@ -648,11 +650,11 @@
it 'Garbage collector' do
process_1 = create AliasJob
process_1.enqueue
4.times { execute queue }
-
+
process_2 = create AliasJob
process_2.enqueue
execute queue
process_3 = create BasicJob
@@ -668,18 +670,18 @@
data_store.keys.select { |k| k.start_with? pid_1 }.count.must_equal 53
data_store.keys.select { |k| k.start_with? pid_2 }.count.must_equal 38
data_store.keys.select { |k| k.start_with? pid_3 }.count.must_equal 7
gc = Asynchronic::GarbageCollector.new env, 0.001
-
+
gc.add_condition('Finalized', &:finalized?)
gc.add_condition('Waiting', &:waiting?)
gc.add_condition('Exception') { raise 'Invalid condition' }
gc.conditions_names.must_equal ['Finalized', 'Waiting', 'Exception']
gc.remove_condition 'Waiting'
-
+
gc.conditions_names.must_equal ['Finalized', 'Exception']
Thread.new do
sleep 0.01
gc.stop
\ No newline at end of file