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

« back to all changes in this revision

Viewing changes to init/tests/test_event.c

  • Committer: Scott James Remnant
  • Date: 2007-02-09 13:26:09 UTC
  • Revision ID: scott@netsplit.com-20070209132609-9n7pe4rvqev1hg8p
* init/job.c (job_handle_event_finished): Function to unblock all
jobs blocked on a given event emission.
(job_new, job_emit_event): Rename blocker to blocked; it's useful for
testing for truth.
* init/job.h: Add prototype, rename member.
* init/tests/test_job.c (test_handle_event_finished): Test it.
(test_new, test_change_state): Update name here too.
* init/event.c (event_finished): Call job_handle_event_finished
function to unblock jobs.
* init/tests/test_event.c (test_poll): Make sure the job gets
unblocked; a few other tests have to change since running event_poll
always unblocks the job if nothing listens to it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
370
370
        TEST_EQ (em1->jobs, 1);
371
371
 
372
372
        TEST_EQ (job->goal, JOB_START);
373
 
        TEST_EQ (job->state, JOB_STARTING);
374
 
        TEST_EQ (job->pid, 0);
 
373
        TEST_EQ (job->state, JOB_RUNNING);
 
374
        TEST_GT (job->pid, 0);
 
375
 
 
376
        waitpid (job->pid, NULL, 0);
375
377
 
376
378
        nih_list_free (&sub->entry);
377
379
        nih_list_free (&job->entry);
394
396
 
395
397
 
396
398
        /* Check that events in the finished state are consumed, leaving
397
 
         * the list empty.  Subscribed processes should be notified and the
398
 
         * event should be freed.
 
399
         * the list empty.  Subscribed processes should be notified, blocked
 
400
         * jobs should be releaed and the event should be freed.
399
401
         */
400
402
        TEST_FEATURE ("with finished event");
401
403
        fflush (stdout);
421
423
 
422
424
        em1 = event_emit ("test", NULL, NULL);
423
425
        em1->id = 0xdeafbeef;
 
426
 
 
427
        job = job_new (NULL, "test");
 
428
        job->goal = JOB_START;
 
429
        job->state = JOB_STARTING;
 
430
        job->pid = 0;
 
431
        job->blocked = em1;
 
432
        job->command = nih_strdup (job, "echo");
 
433
 
424
434
        event_emit_finished (em1);
425
435
 
426
436
        destructor_called = 0;
436
446
        TEST_TRUE (WIFEXITED (status));
437
447
        TEST_EQ (WEXITSTATUS (status), 0);
438
448
 
 
449
        TEST_EQ (job->goal, JOB_START);
 
450
        TEST_EQ (job->state, JOB_RUNNING);
 
451
        TEST_GT (job->pid, 0);
 
452
 
 
453
        waitpid (job->pid, &status, 0);
 
454
        TEST_TRUE (WIFEXITED (status));
 
455
        TEST_EQ (WEXITSTATUS (status), 0);
 
456
 
 
457
        TEST_EQ_P (job->blocked, NULL);
 
458
 
439
459
        TEST_TRUE (destructor_called);
440
460
 
441
461
        nih_list_free (&sub->entry);
482
502
        TEST_TRUE (destructor_called);
483
503
 
484
504
        TEST_EQ (job->goal, JOB_START);
485
 
        TEST_EQ (job->state, JOB_STARTING);
486
 
        TEST_EQ (job->pid, 0);
 
505
        TEST_EQ (job->state, JOB_RUNNING);
 
506
        TEST_GT (job->pid, 0);
 
507
 
 
508
        waitpid (job->pid, NULL, 0);
487
509
 
488
510
        TEST_EQ_STR (job->cause->event.name, "test/failed");
489
511