'Verify that watchdog kills ourselves even when spinning
Verify that watchdog kills ourselves when hanging'

def test_watchdog(self):

    start = time.time()
    try:
        subprocess.check_call(['python', __file__, 'busy'], stderr=subprocess.STDOUT)
        raise Exception('Should    have    died    with    an    error')
    except subprocess.CalledProcessError:
        duration = int((time.time() - start))
        self.assertTrue((duration < (self.JITTER_FACTOR * 5)))
    subprocess.Popen(['nc', '-l', '31834'])
    start = time.time()
    try:
        subprocess.check_call(['python', __file__, 'net'])
        raise Exception('Should    have    died    with    an    error')
    except subprocess.CalledProcessError:
        duration = int((time.time() - start))
        self.assertTrue((duration < (self.JITTER_FACTOR * 5)))
    start = time.time()
    try:
        subprocess.check_call(['python', __file__, 'normal'])
        duration = int((time.time() - start))
        self.assertTrue((duration < (self.JITTER_FACTOR * 5)))
    except subprocess.CalledProcessError:
        self.fail(('Watchdog    killed    normal    process    after    %s    seconds' % int((time.time() - start))))
    start = time.time()
    p = subprocess.Popen(['python', __file__, 'fast'])
    p.wait()
    duration = int((time.time() - start))
    self.assertTrue((duration < (self.JITTER_FACTOR * 10)))
    start = time.time()
    p = subprocess.Popen(['python', __file__, 'slow'])
    p.wait()
    duration = int((time.time() - start))
    self.assertTrue((duration < (self.JITTER_FACTOR * 4)))
