def test_fail_at_first_fork(self): """run_in_daemon fails at first fork... """ from daemon import run_in_daemon global good_forks good_forks = [False] self.redirect_output() run_in_daemon(hello_world) expected_out = """\ fork #1 failed: (12) fork: Resource temporarily unavailable """ out = sys.stdout.getvalue() self.restore_output() self.assertEqual(out, expected_out)
def test_fail_at_second_fork(self): """run_in_daemon fails at second fork... """ from daemon import run_in_daemon # (we need the third one to work, because fork is used to call # the logger). global good_forks good_forks = [True, False, True] self.redirect_output() run_in_daemon(hello_world) # Not exactly sure why we do not get the output from # the logger, but might be normal??? expected_out = """\ """ out = sys.stdout.getvalue() self.restore_output() self.assertEqual(out, expected_out, out)
def post_receive(updated_refs, submitter_email): """Implement the post-receive hook for all given updated_refs. PARAMETERS updated_refs: An OrderedDict, indexed by the name of the ref being updated, and containing 2-elements tuple. This tuple contains the previous revision, and the new revision of the reference. submitter_email: Same as AbstractUpdate.__init__. """ refs = git_show_ref() for ref_name in updated_refs.keys(): (old_rev, new_rev) = updated_refs[ref_name] post_receive_one(ref_name, old_rev, new_rev, refs, submitter_email) # Flush the email queue. Since this involves creating a daemon, # only do so if there is at least one email to be sent. email_queue = EmailQueue() if email_queue.queue: run_in_daemon(email_queue.flush)
global good_forks good_fork = good_forks.pop(0) if good_fork: pid = real_fork() return pid else: raise OSError(errno.ENOMEM, "fork: Resource temporarily unavailable") real_fork = os.fork os.fork = utest_fork print("DEBUG: Test run_in_daemon failing at the first fork...") good_forks = [False] run_in_daemon(hello_world) # FIXME: We would like to test the case where run_in_daemon fails at # the second fork, but for some reason, this causes problems with # coverage testing, due to the at_exit handler trying to save coverage # results in a file located in "/". This daemonize code has been # pretty much unchanged since it was introduced, so accept not covering # this part. # # print("DEBUG: Test run_in_daemon failing at the second fork...") # # # (we need the third one to work, because fork is used to call the logger). # good_forks = [True, False, True] # # run_in_daemon(hello_world)