| 1 | program test_job_lifecycle |
| 2 | use fgof_jobs, only : & |
| 3 | attach_job, & |
| 4 | clear_job_handle, & |
| 5 | clear_job_result, & |
| 6 | complete_job, & |
| 7 | configure_job, & |
| 8 | job_is_configured, & |
| 9 | job_is_finished, & |
| 10 | job_is_running, & |
| 11 | job_needs_cleanup, & |
| 12 | make_job_spec, & |
| 13 | release_job |
| 14 | use fgof_jobs_types, only : job_handle, job_result, job_spec |
| 15 | implicit none |
| 16 | |
| 17 | type(job_spec) :: spec |
| 18 | type(job_handle) :: handle |
| 19 | type(job_result) :: result_value |
| 20 | |
| 21 | spec = make_job_spec("worker", background=.true.) |
| 22 | handle = clear_job_handle() |
| 23 | |
| 24 | call configure_job(handle, spec) |
| 25 | if (.not. job_is_configured(handle)) error stop "configure_job should mark the handle configured" |
| 26 | if (.not. handle%background) error stop "configure_job should copy background intent" |
| 27 | if (job_is_running(handle)) error stop "configure_job should not start a job running" |
| 28 | if (handle%pid /= 0) error stop "configure_job should keep pid clear before attach" |
| 29 | |
| 30 | call attach_job(handle, 42) |
| 31 | if (.not. job_is_running(handle)) error stop "attach_job should mark a configured job running" |
| 32 | if (handle%pid /= 42) error stop "attach_job should record pid" |
| 33 | if (handle%process_group /= 42) error stop "attach_job should default process group to pid" |
| 34 | if (.not. handle%owns_process) error stop "attach_job should own the process by default" |
| 35 | if (.not. job_needs_cleanup(handle)) error stop "attach_job should request cleanup while owned and running" |
| 36 | if (job_is_finished(handle)) error stop "attach_job should not mark the job finished" |
| 37 | |
| 38 | call release_job(handle) |
| 39 | if (handle%owns_process) error stop "release_job should relinquish process ownership" |
| 40 | if (job_needs_cleanup(handle)) error stop "release_job should clear cleanup obligations" |
| 41 | if (.not. job_is_running(handle)) error stop "release_job should not stop runtime tracking" |
| 42 | |
| 43 | handle = clear_job_handle() |
| 44 | call configure_job(handle, spec) |
| 45 | call attach_job(handle, 99, process_group=17, owns_process=.false.) |
| 46 | if (handle%process_group /= 17) error stop "attach_job should preserve explicit process-group values" |
| 47 | if (handle%owns_process) error stop "attach_job should accept explicit non-owning tracking" |
| 48 | if (job_needs_cleanup(handle)) error stop "non-owning tracking should not request cleanup" |
| 49 | |
| 50 | result_value = clear_job_result() |
| 51 | result_value%exit_code = 7 |
| 52 | result_value%exited = .true. |
| 53 | call complete_job(handle, result_value) |
| 54 | if (job_is_running(handle)) error stop "complete_job should stop runtime tracking" |
| 55 | if (.not. job_is_finished(handle)) error stop "complete_job should mark the job finished when a result is available" |
| 56 | if (job_needs_cleanup(handle)) error stop "complete_job should clear cleanup obligations" |
| 57 | if (.not. handle%result%available) error stop "complete_job should mark the embedded result available" |
| 58 | if (handle%result%exit_code /= 7) error stop "complete_job should preserve result payloads" |
| 59 | end program test_job_lifecycle |
| 60 |