Here's a test case for this
TEST_FEATURE ("with respawn limit and second job"); event = (Event *)job2->stop_events.next; nih_list_add (&job2->start_events, &event->entry);
em = event_emit ("wibble", NULL, NULL); em->progress = EVENT_HANDLING;
TEST_ALLOC_FAIL { em->jobs = 0;
job1->goal = JOB_STOP; job1->state = JOB_WAITING; job1->cause = NULL;
job2->goal = JOB_STOP; job2->state = JOB_WAITING; job2->cause = NULL;
/* job2 hashes first */ job2->respawn_limit = 10; job2->respawn_interval = 1000; job2->respawn_time = time (NULL); job2->respawn_count = 10;
TEST_DIVERT_STDERR (output) { job_handle_event (em); } rewind (output);
TEST_EQ (em->jobs, 1); TEST_EQ (em->progress, EVENT_HANDLING);
TEST_EQ (job1->goal, JOB_STOP); TEST_EQ (job1->state, JOB_WAITING); TEST_EQ_P (job1->cause, NULL);
TEST_EQ (job2->goal, JOB_START); TEST_EQ (job2->state, JOB_STARTING); TEST_EQ_P (job2->cause, em);
TEST_FILE_EQ (output, "test: foo respawning too fast, stopped\n$ TEST_FILE_END (output); TEST_FILE_RESET (output); }
nih_list_free (&em->event.entry);
nih_list_free (&job2->entry);
Here's a test case for this
event = (Event *)job2-
em = event_emit ("wibble", NULL, NULL);
em->progress = EVENT_HANDLING;
/* job2 hashes first */
job2- >respawn_ limit = 10;
job2- >respawn_ interval = 1000;
job2- >respawn_ time = time (NULL);
job2- >respawn_ count = 10;
job_handle_event (em);
}
TEST_EQ (em->jobs, 1);
TEST_ EQ (em->progress, EVENT_HANDLING);
TEST_EQ (job1->state, JOB_WAITING);
TEST_EQ (job2->state, JOB_STARTING);
}
nih_list_free (&em->event.entry);
nih_list_free (&job2->entry);