Esempio n. 1
0
 def testContextIsRestoredWhenExceptionsThrown(self):
     """
 When an error occurs in a deferred, context should be restored appropriately
 This test has a follow up that imposes an ordering requirement based on method name.
 """
     self.assertFalse(context.has('foo'))
     try:
         with context.set(foo='bar'):
             self.assert_(context.has('foo'))
             yield threads.deferToThread(self.crashy)
     except AssertionError:
         pass
     self.assertFalse(context.has('foo'))
Esempio n. 2
0
 def testContextIsRestoredWhenExceptionsThrown(self):
   """
   When an error occurs in a deferred, context should be restored appropriately
   This test has a follow up that imposes an ordering requirement based on method name.
   """
   self.assertFalse(context.has('foo'))
   try:
     with context.set(foo='bar'):
       self.assert_(context.has('foo'))
       yield threads.deferToThread(self.crashy)
   except AssertionError:
     pass
   self.assertFalse(context.has('foo'))
Esempio n. 3
0
    def testSettingGettingAndHavingContext(self):
        """Should be able to set context, get it, and check for membership"""
        self.assertRaises(KeyError, context.get, 'foo')

        with context.set(foo='bar'):
            self.assertEquals('bar', context.get('foo'))

        self.assertFalse(context.has('foo'))
Esempio n. 4
0
  def testSettingGettingAndHavingContext(self):
    """Should be able to set context, get it, and check for membership"""
    self.assertRaises(KeyError, context.get, 'foo')

    with context.set(foo='bar'):
      self.assertEquals('bar', context.get('foo'))

    self.assertFalse(context.has('foo'))
    def testInlineCallbacks(self):
        """Test context saving across I/O."""
        with context.set(someValue=12345):
            yield time.sleep(0.001)
            self.assertFalse(context.has('anotherValue'))
            self.assertEqual(12345, context.get('someValue'))
            self.assertTrue(context.has('someValue'))

            with context.set(anotherValue='abcde'):
                yield client.getPage('http://greplin.com')
                self.assertEqual('abcde', context.get('anotherValue'))
                self.assertEqual(12345, context.get('someValue'))

            yield threads.deferToThread(lambda: None)
            self.assertFalse(context.has('anotherValue'))
            self.assertEqual(12345, context.get('someValue'))
            self.assertTrue(context.has('someValue'))

        self.assertFalse(context.has('someValue'))
  def testInlineCallbacks(self):
    """Test context saving across I/O."""
    with context.set(someValue = 12345):
      yield time.sleep(0.001)
      self.assertFalse(context.has('anotherValue'))
      self.assertEqual(12345, context.get('someValue'))
      self.assertTrue(context.has('someValue'))

      with context.set(anotherValue = 'abcde'):
        yield client.getPage('http://greplin.com')
        self.assertEqual('abcde', context.get('anotherValue'))
        self.assertEqual(12345, context.get('someValue'))

      yield threads.deferToThread(lambda: None)
      self.assertFalse(context.has('anotherValue'))
      self.assertEqual(12345, context.get('someValue'))
      self.assertTrue(context.has('someValue'))

    self.assertFalse(context.has('someValue'))
Esempio n. 7
0
    def testDoesntMingleContextAcrossUnyieldedDeferred(self):
        """Deferreds that exist at the same time should not have interacting contexts"""
        self.assertFalse(context.has('a'))
        self.assertFalse(context.has('b'))
        a = self.notCrashySleep(0.01, a=1)
        self.assertFalse(context.has('a'))
        self.assertFalse(context.has('b'))
        b = self.notCrashySleep(0.001, b=2)
        self.assertFalse(context.has('a'))
        self.assertFalse(context.has('b'))

        yield sleep(0.02)
        yield DeferredList([a, b])
Esempio n. 8
0
  def testDoesntMingleContextAcrossUnyieldedDeferred(self):
    """Deferreds that exist at the same time should not have interacting contexts"""
    self.assertFalse(context.has('a'))
    self.assertFalse(context.has('b'))
    a = self.notCrashySleep(0.01, a=1)
    self.assertFalse(context.has('a'))
    self.assertFalse(context.has('b'))
    b = self.notCrashySleep(0.001, b=2)
    self.assertFalse(context.has('a'))
    self.assertFalse(context.has('b'))

    yield sleep(0.02)
    yield DeferredList([a, b])