Example #1
0
def test_blockdetection(patching):
    signals = patching('celery.utils.debug.signals')
    with debug.blockdetection(10):
        signals.arm_alarm.assert_called_with(10)
        signals.__setitem__.assert_called_with('ALRM', debug._on_blocking)
    signals.__setitem__.assert_called_with('ALRM', signals['ALRM'])
    signals.reset_alarm.assert_called_with()
Example #2
0
def test_blockdetection(patching):
    signals = patching('celery.utils.debug.signals')
    with debug.blockdetection(10):
        signals.arm_alarm.assert_called_with(10)
        signals.__setitem__.assert_called_with('ALRM', debug._on_blocking)
    signals.__setitem__.assert_called_with('ALRM', signals['ALRM'])
    signals.reset_alarm.assert_called_with()
Example #3
0
 def runtest(self, fun, n=50, index=0, repeats=1):
     with blockdetection(self.block_timeout):
         t = time()
         i = 0
         failed = False
         self.progress = Progress(fun, i, n, index, repeats, t, 0)
         _marker.delay(pstatus(self.progress))
         try:
             for i in range(n):
                 self.progress = Progress(fun, i, n, index, repeats, t, 0)
                 print(pstatus(self.progress), end=' ')
                 try:
                     fun()
                     print('-> done')
                 except Exception as exc:
                     print('-> {0!r}'.format(exc))
         except Exception:
             failed = True
             raise
         finally:
             print('{0} {1} iterations in {2}s'.format(
                 'failed after' if failed else 'completed',
                 i + 1, humanize_seconds(time() - t),
             ))
             if not failed:
                 self.progress = Progress(fun, i, n, index, repeats, t, 1)
Example #4
0
 def runtest(self, fun, n=50, index=0, repeats=1):
     with blockdetection(self.block_timeout):
         t = time()
         i = 0
         failed = False
         self.progress = Progress(fun, i, n, index, repeats, t, 0)
         _marker.delay(pstatus(self.progress))
         try:
             for i in range(n):
                 self.progress = Progress(fun, i, n, index, repeats, t, 0)
                 print(pstatus(self.progress), end=' ')
                 try:
                     fun()
                     print('-> done')
                 except Exception as exc:
                     print('-> {0!r}'.format(exc))
         except Exception:
             failed = True
             raise
         finally:
             print('{0} {1} iterations in {2}s'.format(
                 'failed after' if failed else 'completed',
                 i + 1,
                 humanize_seconds(time() - t),
             ))
             if not failed:
                 self.progress = Progress(fun, i, n, index, repeats, t, 1)
Example #5
0
 def runtest(self, fun, n=50):
     with blockdetection(self.block_timeout):
         t = time()
         i = 0
         failed = False
         print("-%s(%s)" % (fun.__name__, n))
         try:
             for i in range(n):
                 print(i)
                 fun()
         except Exception:
             failed = True
             raise
         finally:
             print("{0} {1} iterations in {2}s".format("failed after" if failed else "completed", i + 1, time() - t))
Example #6
0
 def runtest(self, fun, n=50):
     with blockdetection(self.block_timeout):
         t = time()
         i = 0
         failed = False
         marker('{0}({1})'.format(fun.__name__, n))
         try:
             for i in range(n):
                 print(i)
                 fun()
         except Exception:
             failed = True
             raise
         finally:
             print('{0} {1} iterations in {2}s'.format(
                 'failed after' if failed else 'completed',
                 i + 1, time() - t,
             ))
Example #7
0
 def runtest(self, fun, n=50, index=0, repeats=1):
     n = getattr(fun, '__iterations__', None) or n
     print('{0}: [[[{1}({2})]]]'.format(repeats, fun.__name__, n))
     with blockdetection(self.block_timeout):
         with self.fbi.investigation():
             runtime = elapsed = monotonic()
             i = 0
             failed = False
             self.progress = Progress(
                 fun, i, n, index, repeats, elapsed, runtime, 0,
             )
             _marker.delay(pstatus(self.progress))
             try:
                 for i in range(n):
                     runtime = monotonic()
                     self.progress = Progress(
                         fun, i + 1, n, index, repeats, runtime, elapsed, 0,
                     )
                     try:
                         fun()
                     except StopSuite:
                         raise
                     except Exception as exc:
                         print('-> {0!r}'.format(exc))
                         import traceback
                         print(traceback.format_exc())
                         print(pstatus(self.progress))
                     else:
                         print(pstatus(self.progress))
             except Exception:
                 failed = True
                 self.speaker.beep()
                 raise
             finally:
                 print('{0} {1} iterations in {2}'.format(
                     'failed after' if failed else 'completed',
                     i + 1, humanize_seconds(monotonic() - elapsed),
                 ))
                 if not failed:
                     self.progress = Progress(
                         fun, i + 1, n, index, repeats, runtime, elapsed, 1,
                     )
Example #8
0
 def runtest(self, fun, n=50, index=0):
     with blockdetection(self.block_timeout):
         t = time()
         i = 0
         failed = False
         marker('{0}: {1}({2})'.format(index, fun.__name__, n))
         try:
             for i in range(n):
                 print('{0} ({1})'.format(i, fun.__name__), end=' ')
                 try:
                     fun()
                     print('-> done')
                 except Exception as exc:
                     print('-> {}'.format(exc))
         except Exception:
             failed = True
             raise
         finally:
             print('{0} {1} iterations in {2}s'.format(
                 'failed after' if failed else 'completed',
                 i + 1, humanize_seconds(time() - t),
             ))
Example #9
0
 def runtest(self, fun, n=50, index=0, repeats=1):
     print('{0}: [[[{1}({2})]]]'.format(repeats, fun.__name__, n))
     with blockdetection(self.block_timeout):
         with self.fbi.investigation():
             runtime = elapsed = monotonic()
             i = 0
             failed = False
             self.progress = Progress(
                 fun, i, n, index, repeats, elapsed, runtime, 0,
             )
             _marker.delay(pstatus(self.progress))
             try:
                 for i in range(n):
                     runtime = monotonic()
                     self.progress = Progress(
                         fun, i + 1, n, index, repeats, runtime, elapsed, 0,
                     )
                     try:
                         fun()
                     except StopSuite:
                         raise
                     except Exception as exc:
                         print('-> {0!r}'.format(exc))
                         print(pstatus(self.progress))
                     else:
                         print(pstatus(self.progress))
             except Exception:
                 failed = True
                 self.speaker.beep()
                 raise
             finally:
                 print('{0} {1} iterations in {2}s'.format(
                     'failed after' if failed else 'completed',
                     i + 1, humanize_seconds(monotonic() - elapsed),
                 ))
                 if not failed:
                     self.progress = Progress(
                         fun, i + 1, n, index, repeats, runtime, elapsed, 1,
                     )
Example #10
0
    def runtest(self, fun, n=50, index=0, repeats=1):
        n = getattr(fun, '__iterations__', None) or n
        header = '[[[{0}({1})]]]'.format(fun.__name__, n)
        if repeats > 1:
            header = '{0} #{1}'.format(header, repeats)
        self.print(header)
        with blockdetection(self.block_timeout):
            with self.fbi.investigation():
                runtime = elapsed = monotonic()
                i = 0
                failed = False
                self.progress = Progress(
                    fun, i, n, index, repeats, elapsed, runtime, 0,
                )
                _marker.delay(pstatus(self.progress))

                try:
                    for i in range(n):
                        runtime = monotonic()
                        self.progress = Progress(
                            fun, i + 1, n, index, repeats, runtime, elapsed, 0,
                        )
                        self.execute_test(fun)

                except Exception:
                    failed = True
                    self.speaker.beep()
                    raise
                finally:
                    if n > 1 or failed:
                        self.print('{0} {1} iterations in {2}'.format(
                            'failed after' if failed else 'completed',
                            i + 1, humanize_seconds(monotonic() - elapsed),
                        ), file=self.stderr if failed else self.stdout)
                    if not failed:
                        self.progress = Progress(
                            fun, i + 1, n, index, repeats, runtime, elapsed, 1,
                        )
Example #11
0
 def test_context(self, signals):
     with debug.blockdetection(10):
         signals.arm_alarm.assert_called_with(10)
         signals.__setitem__.assert_called_with('ALRM', debug._on_blocking)
     signals.__setitem__.assert_called_with('ALRM', signals['ALRM'])
     signals.reset_alarm.assert_called_with()
Example #12
0
 def test_context(self, signals):
     with debug.blockdetection(10):
         signals.arm_alarm.assert_called_with(10)
         signals.__setitem__.assert_called_with('ALRM', debug._on_blocking)
     signals.__setitem__.assert_called_with('ALRM', signals['ALRM'])
     signals.reset_alarm.assert_called_with()