spec/process/life_cycle_examples.rb in asynchronic-1.4.0 vs spec/process/life_cycle_examples.rb in asynchronic-1.5.0

- old
+ new

@@ -491,75 +491,167 @@ process.enqueue execute queue - process.full_status.must_equal AbortQueuedAfertErrorJob => :waiting, - AbortQueuedAfertErrorJob::Child_1 => :queued, - AbortQueuedAfertErrorJob::Child_2 => :queued, - AbortQueuedAfertErrorJob::Child_3 => :queued, - AbortQueuedAfertErrorJob::Child_4 => :queued + process.full_status.must_equal 'AbortQueuedAfertErrorJob' => :waiting, + 'AbortQueuedAfertErrorJob::Child_1' => :queued, + 'AbortQueuedAfertErrorJob::Child_2' => :queued, + 'AbortQueuedAfertErrorJob::Child_3' => :queued, + 'AbortQueuedAfertErrorJob::Child_4' => :queued execute queue - process.full_status.must_equal AbortQueuedAfertErrorJob => :waiting, - AbortQueuedAfertErrorJob::Child_1 => :waiting, - 'Child_1_1' => :queued, - 'Child_1_2' => :queued, - AbortQueuedAfertErrorJob::Child_2 => :queued, - AbortQueuedAfertErrorJob::Child_3 => :queued, - AbortQueuedAfertErrorJob::Child_4 => :queued + process.full_status.must_equal 'AbortQueuedAfertErrorJob' => :waiting, + 'AbortQueuedAfertErrorJob::Child_1' => :waiting, + 'Child_1_1' => :queued, + 'Child_1_2' => :queued, + 'AbortQueuedAfertErrorJob::Child_2' => :queued, + 'AbortQueuedAfertErrorJob::Child_3' => :queued, + 'AbortQueuedAfertErrorJob::Child_4' => :queued execute queue - process.full_status.must_equal AbortQueuedAfertErrorJob => :waiting, - AbortQueuedAfertErrorJob::Child_1 => :waiting, - 'Child_1_1' => :queued, - 'Child_1_2' => :queued, - AbortQueuedAfertErrorJob::Child_2 => :completed, - AbortQueuedAfertErrorJob::Child_3 => :queued, - AbortQueuedAfertErrorJob::Child_4 => :queued + process.full_status.must_equal 'AbortQueuedAfertErrorJob' => :waiting, + 'AbortQueuedAfertErrorJob::Child_1' => :waiting, + 'Child_1_1' => :queued, + 'Child_1_2' => :queued, + 'AbortQueuedAfertErrorJob::Child_2' => :completed, + 'AbortQueuedAfertErrorJob::Child_3' => :queued, + 'AbortQueuedAfertErrorJob::Child_4' => :queued execute queue - process.full_status.must_equal AbortQueuedAfertErrorJob => :aborted, - AbortQueuedAfertErrorJob::Child_1 => :waiting, - 'Child_1_1' => :queued, - 'Child_1_2' => :queued, - AbortQueuedAfertErrorJob::Child_2 => :completed, - AbortQueuedAfertErrorJob::Child_3 => :aborted, - AbortQueuedAfertErrorJob::Child_4 => :queued + process.full_status.must_equal 'AbortQueuedAfertErrorJob' => :aborted, + 'AbortQueuedAfertErrorJob::Child_1' => :waiting, + 'Child_1_1' => :queued, + 'Child_1_2' => :queued, + 'AbortQueuedAfertErrorJob::Child_2' => :completed, + 'AbortQueuedAfertErrorJob::Child_3' => :aborted, + 'AbortQueuedAfertErrorJob::Child_4' => :queued execute queue - process.full_status.must_equal AbortQueuedAfertErrorJob => :aborted, - AbortQueuedAfertErrorJob::Child_1 => :waiting, - 'Child_1_1' => :queued, - 'Child_1_2' => :queued, - AbortQueuedAfertErrorJob::Child_2 => :completed, - AbortQueuedAfertErrorJob::Child_3 => :aborted, - AbortQueuedAfertErrorJob::Child_4 => :aborted + process.full_status.must_equal 'AbortQueuedAfertErrorJob' => :aborted, + 'AbortQueuedAfertErrorJob::Child_1' => :waiting, + 'Child_1_1' => :queued, + 'Child_1_2' => :queued, + 'AbortQueuedAfertErrorJob::Child_2' => :completed, + 'AbortQueuedAfertErrorJob::Child_3' => :aborted, + 'AbortQueuedAfertErrorJob::Child_4' => :aborted execute queue - process.full_status.must_equal AbortQueuedAfertErrorJob => :aborted, - AbortQueuedAfertErrorJob::Child_1 => :aborted, - 'Child_1_1' => :aborted, - 'Child_1_2' => :queued, - AbortQueuedAfertErrorJob::Child_2 => :completed, - AbortQueuedAfertErrorJob::Child_3 => :aborted, - AbortQueuedAfertErrorJob::Child_4 => :aborted + process.full_status.must_equal 'AbortQueuedAfertErrorJob' => :aborted, + 'AbortQueuedAfertErrorJob::Child_1' => :aborted, + 'Child_1_1' => :aborted, + 'Child_1_2' => :queued, + 'AbortQueuedAfertErrorJob::Child_2' => :completed, + 'AbortQueuedAfertErrorJob::Child_3' => :aborted, + 'AbortQueuedAfertErrorJob::Child_4' => :aborted execute queue - process.full_status.must_equal AbortQueuedAfertErrorJob => :aborted, - AbortQueuedAfertErrorJob::Child_1 => :aborted, - 'Child_1_1' => :aborted, - 'Child_1_2' => :aborted, - AbortQueuedAfertErrorJob::Child_2 => :completed, - AbortQueuedAfertErrorJob::Child_3 => :aborted, - AbortQueuedAfertErrorJob::Child_4 => :aborted + process.full_status.must_equal 'AbortQueuedAfertErrorJob' => :aborted, + 'AbortQueuedAfertErrorJob::Child_1' => :aborted, + 'Child_1_1' => :aborted, + 'Child_1_2' => :aborted, + 'AbortQueuedAfertErrorJob::Child_2' => :completed, + 'AbortQueuedAfertErrorJob::Child_3' => :aborted, + 'AbortQueuedAfertErrorJob::Child_4' => :aborted process.real_error.must_equal 'Forced error' + end + + it 'Manual abort' do + process = create NestedJob, input: 10 + + process.enqueue + + execute queue + + process.full_status.must_equal 'NestedJob' => :waiting, + 'NestedJob::Level1' => :queued + + execute queue + + 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, + 'NestedJob::Level1::Level2' => :queued + + execute queue + + process.full_status.must_equal 'NestedJob' => :aborted, + 'NestedJob::Level1' => :aborted, + 'NestedJob::Level1::Level2' => :aborted + end + + it 'Remove process' do + process_1 = create AliasJob + process_2 = create AliasJob + + process_1.enqueue + + 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_2 }.count.must_equal 7 + + process_1.destroy + + 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 7 + end + + it 'Garbage collector' do + process_1 = create AliasJob + process_1.enqueue + 4.times { execute queue } + + process_2 = create AliasJob + process_2.enqueue + execute queue + + pid_1 = process_1.id + 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 + + gc = Asynchronic::GarbageCollector.new env, 0.001 + + gc.add_condition('Completed', &:completed?) + gc.add_condition('Waiting', &:waiting?) + gc.add_condition('Exception') { raise 'Invalid condition' } + + gc.conditions_names.must_equal ['Completed', 'Waiting', 'Exception'] + + gc.remove_condition 'Waiting' + + gc.conditions_names.must_equal ['Completed', 'Exception'] + + Thread.new do + sleep 0.01 + gc.stop + 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 end end \ No newline at end of file