def test_call_eol(self):
   cmd = [sys.executable, SLEEP, '0.001']
   # 0 means no timeout, like None.
   output, code = run_test_cases.call_with_timeout(
       cmd, 0, universal_newlines=True)
   self.assertEquals('Sleeping.\nSlept.\n', output)
   self.assertEquals(0, code)
 def test_call_timed_out_kill(self):
   cmd = [sys.executable, SLEEP, '100']
   # On a loaded system, this can be tight.
   output, code = run_test_cases.call_with_timeout(cmd, timeout=1)
   self.assertEquals(to_native_eol('Sleeping.\n'), output)
   if sys.platform == 'win32':
     self.assertEquals(1, code)
   else:
     self.assertEquals(-9, code)
Example #3
0
 def test_call_timed_out_kill_eol(self):
     cmd = [sys.executable, SLEEP, "100"]
     # On a loaded system, this can be tight.
     output, code = run_test_cases.call_with_timeout(cmd, timeout=1, universal_newlines=True)
     self.assertEquals("Sleeping.\n", output)
     if sys.platform == "win32":
         self.assertEquals(1, code)
     else:
         self.assertEquals(-9, code)
Example #4
0
    def test_call_with_timeout(self):
        timedout = 1 if sys.platform == 'win32' else -9
        # Format is:
        # ( (cmd, stderr_pipe, timeout), (stdout, stderr, returncode) ), ...
        test_data = [
            # 0 means no timeout, like None.
            (
                (['out_sleeping', '0.001', 'out_slept', 'err_print'], None, 0),
                ('Sleeping.\nSlept.\n', None, 0),
            ),
            (
                (['err_print'], subprocess.STDOUT, 0),
                ('printing', None, 0),
            ),
            (
                (['err_print'], subprocess.PIPE, 0),
                ('', 'printing', 0),
            ),

            # On a loaded system, this can be tight.
            (
                (['out_sleeping', 'out_flush', '100', 'out_slept'], None, 0.5),
                ('Sleeping.\n', '', timedout),
            ),
            (
                (
                    # Note that err_flush is necessary on Windows but not on the other
                    # OSes. This means the likelihood of missing stderr output from a
                    # killed child process on Windows is much higher than on other OSes.
                    [
                        'out_sleeping',
                        'out_flush',
                        'err_print',
                        'err_flush',
                        '100',
                        'out_slept',
                    ],
                    subprocess.PIPE,
                    0.5),
                ('Sleeping.\n', 'printing', timedout),
            ),
            (
                (['out_sleeping', '0.001', 'out_slept'], None, 100),
                ('Sleeping.\nSlept.\n', '', 0),
            ),
        ]
        for i, (data, expected) in enumerate(test_data):
            stdout, stderr, code, duration = run_test_cases.call_with_timeout(
                [sys.executable, OUTPUT] + data[0],
                stderr=data[1],
                timeout=data[2])
            self.assertTrue(duration > 0.0001, (data, duration))
            self.assertEqual(
                (i, stdout, stderr, code), (i, to_native_eol(
                    expected[0]), to_native_eol(expected[1]), expected[2]))

            # Try again with universal_newlines=True.
            stdout, stderr, code, duration = run_test_cases.call_with_timeout(
                [sys.executable, OUTPUT] + data[0],
                stderr=data[1],
                timeout=data[2],
                universal_newlines=True)
            self.assertTrue(duration > 0.0001, (data, duration))
            self.assertEqual((i, stdout, stderr, code), (i, ) + expected)
 def test_call_timeout_no_kill_eol(self):
   cmd = [sys.executable, SLEEP, '0.001']
   output, code = run_test_cases.call_with_timeout(
       cmd, timeout=100, universal_newlines=True)
   self.assertEquals('Sleeping.\nSlept.\n', output)
   self.assertEquals(0, code)
 def test_call_timeout_no_kill(self):
   cmd = [sys.executable, SLEEP, '0.001']
   output, code = run_test_cases.call_with_timeout(cmd, timeout=100)
   self.assertEquals(to_native_eol('Sleeping.\nSlept.\n'), output)
   self.assertEquals(0, code)
 def test_call(self):
   cmd = [sys.executable, SLEEP, '0.001']
   # 0 means no timeout, like None.
   output, code = run_test_cases.call_with_timeout(cmd, 0)
   self.assertEquals(to_native_eol('Sleeping.\nSlept.\n'), output)
   self.assertEquals(0, code)
Example #8
0
  def test_call_with_timeout(self):
    timedout = 1 if sys.platform == 'win32' else -9
    # Format is:
    # ( (cmd, stderr_pipe, timeout), (stdout, stderr, returncode) ), ...
    test_data = [
      # 0 means no timeout, like None.
      (
        (['out_sleeping', '0.001', 'out_slept', 'err_print'], None, 0),
        ('Sleeping.\nSlept.\n', None, 0),
      ),
      (
        (['err_print'], subprocess.STDOUT, 0),
        ('printing', None, 0),
      ),
      (
        (['err_print'], subprocess.PIPE, 0),
        ('', 'printing', 0),
      ),

      # On a loaded system, this can be tight.
      (
        (['out_sleeping', 'out_flush', '100', 'out_slept'], None, 0.5),
        ('Sleeping.\n', '', timedout),
      ),
      (
        (
          # Note that err_flush is necessary on Windows but not on the other
          # OSes. This means the likelihood of missing stderr output from a
          # killed child process on Windows is much higher than on other OSes.
          [
            'out_sleeping', 'out_flush', 'err_print', 'err_flush', '100',
            'out_slept',
          ],
          subprocess.PIPE,
          0.5),
        ('Sleeping.\n', 'printing', timedout),
      ),

      (
        (['out_sleeping', '0.001', 'out_slept'], None, 100),
        ('Sleeping.\nSlept.\n', '', 0),
      ),
    ]
    for i, (data, expected) in enumerate(test_data):
      stdout, stderr, code, duration = run_test_cases.call_with_timeout(
          [sys.executable, OUTPUT] + data[0],
          stderr=data[1],
          timeout=data[2])
      self.assertTrue(duration > 0.0001, (data, duration))
      self.assertEqual(
          (i, stdout, stderr, code),
          (i,
            to_native_eol(expected[0]),
            to_native_eol(expected[1]),
            expected[2]))

      # Try again with universal_newlines=True.
      stdout, stderr, code, duration = run_test_cases.call_with_timeout(
          [sys.executable, OUTPUT] + data[0],
          stderr=data[1],
          timeout=data[2],
          universal_newlines=True)
      self.assertTrue(duration > 0.0001, (data, duration))
      self.assertEqual(
          (i, stdout, stderr, code),
          (i,) + expected)