~vorlon/ubuntu/raring/upstart/lp.1199778

« back to all changes in this revision

Viewing changes to init/tests/test_job_process.c

  • Committer: Scott James Remnant
  • Date: 2008-06-07 21:59:56 UTC
  • Revision ID: scott@netsplit.com-20080607215956-qmt4jnmqwb85sku1
* init/job_process.c (job_process_terminated): Don't check the goal
to see whether the main process was allowed to terminate, check the
state.  A termination is only not a failure if we're on the KILLED
state (ie. we killed it), otherwise it can still be a failure even
if it was going to stop anyway.
* init/tests/test_job_process.c (test_handler): Add a test case.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1328
1328
        }
1329
1329
 
1330
1330
 
 
1331
        /* Check that if the process is restarting, and died when we killed
 
1332
         * it, the goal remains as start and a state change is still
 
1333
         * transitioned.  This should also not be considered a failure.
 
1334
         */
 
1335
        TEST_FEATURE ("with restarting process");
 
1336
        TEST_ALLOC_FAIL {
 
1337
                NihTimer *timer = NULL;
 
1338
 
 
1339
                TEST_ALLOC_SAFE {
 
1340
                        job = job_new (class, "");
 
1341
 
 
1342
                        blocked = blocked_new (job, BLOCKED_EVENT, event);
 
1343
                        event_block (event);
 
1344
                        nih_list_add (&job->blocking, &blocked->entry);
 
1345
                }
 
1346
 
 
1347
                job->goal = JOB_START;
 
1348
                job->state = JOB_KILLED;
 
1349
                job->pid[PROCESS_MAIN] = 1;
 
1350
 
 
1351
                TEST_FREE_TAG (blocked);
 
1352
 
 
1353
                job->blocker = NULL;
 
1354
                event->failed = FALSE;
 
1355
 
 
1356
                job->failed = FALSE;
 
1357
                job->failed_process = -1;
 
1358
                job->exit_status = 0;
 
1359
 
 
1360
                TEST_ALLOC_SAFE {
 
1361
                        timer = (void *) nih_strdup (job, "test");
 
1362
                }
 
1363
 
 
1364
                TEST_FREE_TAG (timer);
 
1365
                job->kill_timer = timer;
 
1366
 
 
1367
                job_process_handler (NULL, 1, NIH_CHILD_EXITED, 0);
 
1368
 
 
1369
                TEST_FREE (timer);
 
1370
 
 
1371
                TEST_EQ (job->goal, JOB_START);
 
1372
                TEST_EQ (job->state, JOB_STARTING);
 
1373
                TEST_EQ (job->pid[PROCESS_MAIN], 0);
 
1374
 
 
1375
                TEST_EQ (event->blockers, 1);
 
1376
                TEST_EQ (event->failed, FALSE);
 
1377
 
 
1378
                TEST_LIST_NOT_EMPTY (&job->blocking);
 
1379
                TEST_NOT_FREE (blocked);
 
1380
                TEST_EQ_P (blocked->event, event);
 
1381
                event_unblock (event);
 
1382
 
 
1383
                TEST_NE_P (job->blocker, NULL);
 
1384
 
 
1385
                TEST_LIST_NOT_EMPTY (&job->blocker->blocking);
 
1386
 
 
1387
                blocked = (Blocked *)job->blocker->blocking.next;
 
1388
                TEST_ALLOC_SIZE (blocked, sizeof (Blocked));
 
1389
                TEST_ALLOC_PARENT (blocked, job->blocker);
 
1390
                TEST_EQ (blocked->type, BLOCKED_JOB);
 
1391
                TEST_EQ_P (blocked->job, job);
 
1392
                nih_free (blocked);
 
1393
 
 
1394
                TEST_LIST_EMPTY (&job->blocker->blocking);
 
1395
 
 
1396
                TEST_EQ (job->failed, FALSE);
 
1397
                TEST_EQ (job->failed_process, -1);
 
1398
                TEST_EQ (job->exit_status, 0);
 
1399
 
 
1400
                nih_free (job);
 
1401
        }
 
1402
 
 
1403
 
1331
1404
        /* Check that we can handle the pre-start process of the job exiting,
1332
1405
         * and if it terminates with a good error code, end up in the running
1333
1406
         * state.