272
272
check_event (void *data,
274
274
UpstartMessageType type,
275
276
const char *name,
276
277
char * const *args,
277
278
char * const *env)
279
280
TEST_EQ (pid, getppid ());
280
281
TEST_EQ (type, UPSTART_EVENT);
282
TEST_EQ_U (id, 0xdeafbeef);
283
TEST_EQ_STR (name, "test");
284
TEST_EQ_P (args, NULL);
285
TEST_EQ_P (env, NULL);
291
check_event_finished (void *data,
293
UpstartMessageType type,
300
TEST_EQ (pid, getppid ());
301
TEST_EQ (type, UPSTART_EVENT_FINISHED);
302
TEST_EQ_U (id, 0xdeafbeef);
303
TEST_EQ (failed, FALSE);
281
304
TEST_EQ_STR (name, "test");
282
305
TEST_EQ_P (args, NULL);
283
306
TEST_EQ_P (env, NULL);
339
sub = notify_subscribe (pid, NOTIFY_EVENTS, TRUE);
341
362
job = job_new (NULL, "test");
342
363
job->command = nih_strdup (job, "echo");
345
366
nih_list_add (&job->start_events, &event->entry);
347
368
em1 = event_emit ("test", NULL, NULL, my_emission_cb, &em1);
369
em1->id = 0xdeafbeef;
371
sub = notify_subscribe_event (NULL, pid, em1);
389
411
/* Check that events in the finished state are consumed, leaving
390
* the list empty. The callback for the event should be run and
391
* the event should be freed.
412
* the list empty. Subscribed processes should be notified and
413
* the callback for the event should be run and the event should
393
416
TEST_FEATURE ("with finished event");
395
em1 = event_emit ("test", NULL, NULL, my_emission_cb, &em1);
396
event_emit_finished (em1);
398
destructor_called = 0;
399
nih_alloc_set_destructor (em1, my_destructor);
405
TEST_TRUE (emission_called);
406
TEST_TRUE (destructor_called);
418
TEST_CHILD_WAIT (pid, wait_fd) {
419
NihIoMessage *message;
423
sock = upstart_open ();
425
TEST_CHILD_RELEASE (wait_fd);
427
message = nih_io_message_recv (NULL, sock, &len);
428
assert0 (upstart_message_handle_using (message, message,
429
(UpstartMessageHandler)
430
check_event_finished,
438
em1 = event_emit ("test", NULL, NULL, my_emission_cb, &em1);
439
em1->id = 0xdeafbeef;
441
destructor_called = 0;
442
nih_alloc_set_destructor (em1, my_destructor);
444
sub = notify_subscribe_event (NULL, pid, em1);
447
event_emit_finished (em1);
451
io->watch->watcher (io, io->watch, NIH_IO_READ | NIH_IO_WRITE);
453
waitpid (pid, &status, 0);
454
TEST_TRUE (WIFEXITED (status));
455
TEST_EQ (WEXITSTATUS (status), 0);
457
TEST_TRUE (emission_called);
458
TEST_TRUE (destructor_called);
460
nih_list_free (&sub->entry);
410
463
/* Check that a pending event which doesn't cause any jobs to be
411
464
* changed goes straight into the finished state, thus getting