Example #1
0
    def _call(self, assertion, msg=None, obj=None):
        """
        assertion: what we're asserting
        msg: a static message describing the error
        obj: the specific piece of data, if any, that tripped the assertion

        returns the assertion itself
        """
        if not assertion:
            if self.debug or is_hard_mode():
                raise AssertionError(msg)
            short_tb = get_traceback(skip=self.tb_skip, limit=self.key_limit)
            full_tb = get_traceback(skip=self.tb_skip)
            line = short_tb.strip().split('\n')[-1].strip()
            tb_id = hashlib.md5(short_tb).hexdigest()
            count = ExponentialBackoff.increment(tb_id)
            if not self.use_exponential_backoff or not ExponentialBackoff.should_backoff(
                    tb_id):
                if msg:
                    msg = msg.replace('\n', '\\n')
                breadcrumbs = get_breadcrumbs(
                ) if self.include_breadcrumbs else None
                self.send(
                    SoftAssertInfo(traceback=full_tb,
                                   short_traceback=short_tb,
                                   count=count,
                                   msg=msg,
                                   key=tb_id,
                                   line=line,
                                   obj=obj,
                                   breadcrumbs=breadcrumbs))
        return assertion
Example #2
0
    def _call(self, assertion, msg=None, obj=None):
        """
        assertion: what we're asserting
        msg: a static message describing the error
        obj: the specific piece of data, if any, that tripped the assertion

        returns the assertion itself
        """
        if not assertion:
            if self.debug or is_hard_mode():
                raise AssertionError(msg)
            short_tb = get_traceback(skip=self.tb_skip, limit=self.key_limit)
            full_tb = get_traceback(skip=self.tb_skip)
            line = short_tb.strip().split('\n')[-1].strip()
            tb_id = hashlib.md5(short_tb).hexdigest()
            count = ExponentialBackoff.increment(tb_id)
            if not self.use_exponential_backoff or not ExponentialBackoff.should_backoff(tb_id):
                if msg:
                    msg = msg.replace('\n', '\\n')
                self.send(SoftAssertInfo(traceback=full_tb,
                                         short_traceback=short_tb,
                                         count=count,
                                         msg=msg,
                                         key=tb_id, line=line, obj=obj))
        return assertion
Example #3
0
    def test_backoff(self):
        key = 'new key'

        self.assertFalse(ExponentialBackoff.should_backoff(key))
        self.assertFalse(ExponentialBackoff.should_backoff(key))

        ExponentialBackoff.increment(key)  # first incr is 1
        self.assertFalse(ExponentialBackoff.should_backoff(key))

        ExponentialBackoff.increment(key)  # incr to 2
        self.assertFalse(ExponentialBackoff.should_backoff(key))

        ExponentialBackoff.increment(key)  # incr to 3
        self.assertTrue(ExponentialBackoff.should_backoff(key))

        ExponentialBackoff.increment(key)  # incr to 4
        self.assertFalse(ExponentialBackoff.should_backoff(key))
    def test_backoff(self):
        key = 'new key'

        self.assertFalse(ExponentialBackoff.should_backoff(key))
        self.assertFalse(ExponentialBackoff.should_backoff(key))

        ExponentialBackoff.increment(key)  # first incr is 1
        self.assertFalse(ExponentialBackoff.should_backoff(key))

        ExponentialBackoff.increment(key)  # incr to 2
        self.assertFalse(ExponentialBackoff.should_backoff(key))

        ExponentialBackoff.increment(key)  # incr to 3
        self.assertTrue(ExponentialBackoff.should_backoff(key))

        ExponentialBackoff.increment(key)  # incr to 4
        self.assertFalse(ExponentialBackoff.should_backoff(key))
Example #5
0
def jserror(request):
    stack = request.POST.get('stack', None)
    message = request.POST.get('message', None)
    if stack:
        cache_key = ' '.join(map(lambda l: l.strip(), stack.split('\n'))[:3])
    else:
        cache_key = message

    count = ExponentialBackoff.increment(cache_key)
    if not ExponentialBackoff.should_backoff(cache_key):
        notify_js_exception(request,
                            message=message,
                            details={
                                'filename': request.POST.get('filename', None),
                                'line': request.POST.get('line', None),
                                'page': request.POST.get('page', None),
                                'agent':
                                request.META.get('HTTP_USER_AGENT', None),
                                'js_stack': stack,
                                'count': count,
                            })

    return HttpResponse('')
Example #6
0
def jserror(request):
    stack = request.POST.get('stack', None)
    message = request.POST.get('message', None)
    if stack:
        cache_key = ' '.join(map(lambda l: l.strip(), stack.split('\n'))[:3])
    else:
        cache_key = message

    count = ExponentialBackoff.increment(cache_key)
    if not ExponentialBackoff.should_backoff(cache_key):
        notify_js_exception(
            request,
            message=message,
            details={
                'filename': request.POST.get('filename', None),
                'line': request.POST.get('line', None),
                'page': request.POST.get('page', None),
                'agent': request.META.get('HTTP_USER_AGENT', None),
                'js_stack': stack,
                'count': count,
            }
        )

    return HttpResponse('')
Example #7
0
 def test_backoff_none(self):
     key = None
     ExponentialBackoff.increment(key)  # first incr is 1
     self.assertFalse(ExponentialBackoff.should_backoff(key))
 def test_backoff_none(self):
     key = None
     ExponentialBackoff.increment(key)  # first incr is 1
     self.assertFalse(ExponentialBackoff.should_backoff(key))
Example #9
0
def _is_rate_limited(rate_limit_key):
    exponential_backoff_key = '{}_down'.format(rate_limit_key)
    ExponentialBackoff.increment(exponential_backoff_key)
    return ExponentialBackoff.should_backoff(exponential_backoff_key)