spec/process/life_cycle_examples.rb in asynchronic-1.6.3 vs spec/process/life_cycle_examples.rb in asynchronic-2.0.0

- old
+ new

@@ -8,21 +8,26 @@ data_store.clear queue_engine.clear end def create(type, params={}) - env.create_process type, params + env.create_process(type, params).tap do |process| + process.must_be_initialized + end end def execute(queue) - env.load_process(queue.pop).execute + process = env.load_process(queue.pop) + process.execute + process.must_have_connection_name + process.wont_be :dead? + process.send(:connected?).must_be_true end it 'Basic' do process = create BasicJob, input: 1 - process.must_be_initialized process.must_have_params input: 1 queue.must_be_empty process.enqueue @@ -37,11 +42,10 @@ end it 'Sequential' do process = create SequentialJob, input: 50 - process.must_be_initialized process.must_have_params input: 50 queue.must_be_empty process.enqueue @@ -75,11 +79,10 @@ end it 'Graph' do process = create GraphJob, input: 100 - process.must_be_initialized process.must_have_params input: 100 queue.must_be_empty process.enqueue @@ -131,11 +134,10 @@ end it 'Parallel' do process = create ParallelJob, input: 10, times: 3 - process.must_be_initialized process.must_have_params input: 10, times: 3 queue.must_be_empty process.enqueue @@ -165,11 +167,10 @@ end it 'Nested' do process = create NestedJob, input: 4 - process.must_be_initialized process.must_have_params input: 4 queue.must_be_empty process.enqueue @@ -205,11 +206,10 @@ end it 'Alias' do process = create AliasJob - process.must_be_initialized queue.must_be_empty process.enqueue process.must_be_queued @@ -259,11 +259,10 @@ end it 'Custom queue' do process = create CustomQueueJob, input: 'hello' - process.must_be_initialized process.must_have_params input: 'hello' env.queue(:queue_1).must_be_empty env.queue(:queue_2).must_be_empty env.queue(:queue_3).must_be_empty @@ -300,11 +299,10 @@ end it 'Exception' do process = create ExceptionJob - process.must_be_initialized queue.must_be_empty process.enqueue process.must_be_queued @@ -318,11 +316,10 @@ end it 'Inner exception' do process = create InnerExceptionJob - process.must_be_initialized queue.must_be_empty process.enqueue process.must_be_queued @@ -346,11 +343,10 @@ end it 'Forward reference' do process = create ForwardReferenceJob - process.must_be_initialized queue.must_be_empty process.enqueue process.must_be_queued @@ -389,11 +385,10 @@ end it 'Job with retries' do process = create WithRetriesJob - process.must_be_initialized queue.must_be_empty process.enqueue process.must_be_queued @@ -602,11 +597,11 @@ execute queue pid_1 = process_1.id pid_2 = process_2.id - data_store.keys.select { |k| k.start_with? pid_1 }.count.must_equal 37 + data_store.keys.select { |k| k.start_with? pid_1 }.count.must_equal 38 data_store.keys.select { |k| k.start_with? pid_2 }.count.must_equal 7 process_1.destroy data_store.keys.select { |k| k.start_with? pid_1 }.count.must_equal 0 @@ -626,12 +621,12 @@ pid_2 = process_2.id process_1.must_be_completed process_2.must_be_waiting - data_store.keys.select { |k| k.start_with? pid_1 }.count.must_equal 49 - data_store.keys.select { |k| k.start_with? pid_2 }.count.must_equal 37 + 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 gc = Asynchronic::GarbageCollector.new env, 0.001 gc.add_condition('Completed', &:completed?) gc.add_condition('Waiting', &:waiting?) @@ -649,17 +644,16 @@ end gc.start data_store.keys.select { |k| k.start_with? pid_1 }.count.must_equal 0 - data_store.keys.select { |k| k.start_with? pid_2 }.count.must_equal 37 + data_store.keys.select { |k| k.start_with? pid_2 }.count.must_equal 38 end it 'Before finalize hook when completed' do process = create BeforeFinalizeCompletedJob - process.must_be_initialized queue.must_be_empty process.enqueue process.must_be_queued @@ -673,11 +667,10 @@ end it 'Before finalize hook when aborted' do process = create BeforeFinalizeAbortedJob - process.must_be_initialized queue.must_be_empty process.enqueue process.must_be_queued @@ -691,11 +684,10 @@ end it 'Before finalize raises exception and aborts' do process = create BeforeFinalizeRaisesExceptionJob - process.must_be_initialized queue.must_be_empty process.enqueue process.must_be_queued @@ -709,10 +701,9 @@ end it 'Before finalize raises exception on aborted job' do process = create BeforeFinalizeExceptionOnAbortedJob - process.must_be_initialized queue.must_be_empty process.enqueue process.must_be_queued \ No newline at end of file