'Check that the cache sets and restores logcontexts correctly when
the lookup function throws an exception'

def test_cache_logcontexts_with_exception(self):

    class Cls(object, ):
        @descriptors.cached()
        def fn(self, arg1):
            @defer.inlineCallbacks
            def inner_fn():
                (yield async.run_on_reactor())
                raise SynapseError(400, 'blah')
            return inner_fn()
    @defer.inlineCallbacks
    def do_lookup():
        with logcontext.LoggingContext() as c1:
            c1.name = 'c1'
            try:
                (yield obj.fn(1))
                self.fail('No    exception    thrown')
            except SynapseError:
                pass
            self.assertEqual(logcontext.LoggingContext.current_context(), c1)
    obj = Cls()
    d1 = do_lookup()
    self.assertEqual(logcontext.LoggingContext.current_context(), logcontext.LoggingContext.sentinel)
    return d1
