------------------------------------------------------------
revno: 1651
committer: Dimitri John Ledkov <dimitri.led...@canonical.com>
branch nick: trunk
timestamp: Sat 2014-07-12 01:40:47 +0100
message:
  Split 'with no such file' test into two scenarios - read handler or 
job_process_handler getting called first.
modified:
  init/tests/test_job_process.c


--
lp:upstart
https://code.launchpad.net/~upstart-devel/upstart/trunk

Your team Upstart Reviewers is subscribed to branch lp:upstart.
To unsubscribe from this branch go to 
https://code.launchpad.net/~upstart-devel/upstart/trunk/+edit-subscription
=== modified file 'init/tests/test_job_process.c'
--- init/tests/test_job_process.c	2014-07-11 19:42:48 +0000
+++ init/tests/test_job_process.c	2014-07-12 00:40:47 +0000
@@ -145,6 +145,20 @@
 	NIH_MUST (nih_main_loop_add_func (NULL, (NihMainLoopCb)event_poll, \
 					  NULL))
 
+#define TEST_INSTALL_CHILD_HANDLERS_WITHOUT_JOB_PROCESS()	\
+	NIH_MUST (nih_child_add_watch (NULL,			\
+				       -1,			\
+				       NIH_CHILD_ALL,		\
+				       test_job_process_handler,\
+				       NULL));			\
+	NIH_MUST (nih_child_add_watch (NULL,			\
+				       -1,			\
+				       NIH_CHILD_ALL,		\
+				       job_process_handler,	\
+				       NULL));			\
+	NIH_MUST (nih_main_loop_add_func (NULL, (NihMainLoopCb)event_poll, \
+					  NULL))
+
 
 #define TEST_CLEAR_CHILD_STATUS()				\
 	do {							\
@@ -506,6 +520,7 @@
 	pid_t            pid;
 	int              i;
 	siginfo_t        siginfo;
+	NihList         *removed_watch;
 
 	log_unflushed_init ();
 	job_class_init ();
@@ -1165,11 +1180,11 @@
 	 * job_process_start() raises a ProcessError and the command doesn't
 	 * have any stored process id for it.
 	 */
-	TEST_FEATURE ("with no such file");
+	TEST_FEATURE ("with no such file (read error)");
 	TEST_HASH_EMPTY (job_classes);
 
 	TEST_RESET_MAIN_LOOP ();
-	TEST_INSTALL_CHILD_HANDLERS ();
+	TEST_INSTALL_CHILD_HANDLERS_WITHOUT_JOB_PROCESS ();
 
 	output = tmpfile ();
 
@@ -1209,6 +1224,54 @@
 		nih_free (class);
 	}
 
+	TEST_RESET_MAIN_LOOP ();
+
+	TEST_FEATURE ("with no such file (child abort)");
+	TEST_HASH_EMPTY (job_classes);
+
+	TEST_RESET_MAIN_LOOP ();
+	TEST_INSTALL_CHILD_HANDLERS_WITHOUT_JOB_PROCESS ();
+
+	output = tmpfile ();
+
+	TEST_ALLOC_FAIL {
+		TEST_ALLOC_SAFE {
+			TEST_HASH_EMPTY (job_classes);
+			class = job_class_new (NULL, "test", NULL);
+			class->console = CONSOLE_NONE;
+			class->process[PROCESS_MAIN] = process_new (class);
+			class->process[PROCESS_MAIN]->script = FALSE;
+			class->process[PROCESS_MAIN]->command = filename;
+
+			job = job_new (class, "foo");
+			job->goal = JOB_START;
+			job->state = JOB_SPAWNED;
+
+			nih_hash_add (job_classes, &class->entry);
+			TEST_CLEAR_CHILD_STATUS ();
+		}
+
+		TEST_DIVERT_STDERR (output) {
+			job_process_start (job, PROCESS_MAIN);
+			pid = job->pid[PROCESS_MAIN];
+			TEST_GT (pid, 0);
+			waitpid (pid, &status, 0);
+			TEST_TRUE (WIFEXITED (status));
+			TEST_EQ (WEXITSTATUS (status), 255);
+			job_process_handler (NULL, pid, NIH_CHILD_EXITED, 255);
+			event_poll ();
+		}
+		rewind (output);
+		
+		TEST_EQ (job->pid[PROCESS_MAIN], 0);
+		TEST_GT (sprintf (buffer, "test: test (foo) main process (%i) terminated with status 255\n", pid), 0);
+		TEST_FILE_EQ (output, buffer);
+		TEST_FILE_END (output);
+		TEST_FILE_RESET (output);
+
+		nih_free (class);
+	}
+
 	TEST_EQ (rmdir (dirname), 0);
 
 	TEST_RESET_MAIN_LOOP ();

-- 
upstart-devel mailing list
upstart-devel@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel

Reply via email to