Example #1
0
    def test_enqueue_wait_partial_relay(self):
        env = Envelope(
            '*****@*****.**',
            ['*****@*****.**', '*****@*****.**', '*****@*****.**'])
        self.store.write(env, IsA(float)).AndReturn('1234')
        self.relay._attempt(env, 0).AndReturn({
            '*****@*****.**':
            None,
            '*****@*****.**':
            TransientRelayError('transient', Reply('450', 'transient')),
            '*****@*****.**':
            PermanentRelayError('permanent', Reply('550', 'permanent'))
        })
        self.store.increment_attempts('1234')
        self.store.set_timestamp('1234', IsA(float))
        self.store.set_recipients_delivered('1234', set([0, 2]))
        self.mox.ReplayAll()

        def backoff(envelope, attempts):
            return 0

        def no_bounce(envelope, reply):
            return None

        queue = Queue(self.store,
                      self.relay,
                      backoff=backoff,
                      bounce_factory=no_bounce,
                      relay_pool=5)
        queue.enqueue(env)
        queue.relay_pool.join()
Example #2
0
 def test_enqueue_wait_partial_relay_expired(self):
     env = Envelope(
         '*****@*****.**',
         ['*****@*****.**', '*****@*****.**', '*****@*****.**'])
     bounce_mock = self.mox.CreateMockAnything()
     bounce_mock(IsA(Envelope), IsA(Reply)).AndReturn(None)
     bounce_mock(IsA(Envelope), IsA(Reply)).AndReturn(None)
     self.store.write(env, IsA(float)).AndReturn('1234')
     self.relay._attempt(env, 0).AndReturn({
         '*****@*****.**':
         TransientRelayError('transient', Reply('450', 'transient 1')),
         '*****@*****.**':
         TransientRelayError('transient', Reply('450', 'transient 1')),
         '*****@*****.**':
         TransientRelayError('transient', Reply('450', 'transient 2'))
     })
     self.store.increment_attempts('1234')
     self.store.remove('1234')
     self.mox.ReplayAll()
     queue = Queue(self.store,
                   self.relay,
                   bounce_factory=bounce_mock,
                   relay_pool=5)
     queue.enqueue(env)
     queue.relay_pool.join()
 def test_enqueue_wait_permanentfail(self):
     self.store.write(self.env, IsA(float)).AndReturn('1234')
     self.relay._attempt(self.env, 0).AndRaise(PermanentRelayError('permanent', Reply('550', 'permanent')))
     self.store.remove('1234')
     self.mox.ReplayAll()
     def no_bounce(envelope, reply):
         return None
     queue = Queue(self.store, self.relay, bounce_factory=no_bounce, relay_pool=5)
     queue.enqueue(self.env)
     queue.relay_pool.join()
 def test_enqueue_wait_permanentfail(self):
     self.store.write(self.env, IsA(float)).AndReturn('1234')
     self.relay._attempt(self.env, 0).AndRaise(PermanentRelayError('permanent', Reply('550', 'permanent')))
     self.store.remove('1234')
     self.mox.ReplayAll()
     def no_bounce(envelope, reply):
         return None
     queue = Queue(self.store, self.relay, bounce_factory=no_bounce, relay_pool=5)
     queue.enqueue(self.env)
     queue.relay_pool.join()
 def test_enqueue_wait_transientfail(self):
     self.store.write(self.env, IsA(float)).AndReturn('1234')
     self.relay._attempt(self.env, 0).AndRaise(TransientRelayError('transient', Reply('450', 'transient')))
     self.store.increment_attempts('1234')
     self.store.set_timestamp('1234', IsA(float))
     self.mox.ReplayAll()
     def backoff(envelope, attempts):
         return 0
     queue = Queue(self.store, self.relay, backoff=backoff, relay_pool=5)
     queue.enqueue(self.env)
     queue.relay_pool.join()
 def test_enqueue_wait_unhandledfail(self):
     self.store.write(self.env, IsA(float)).AndReturn('1234')
     self.relay._attempt(self.env, 0).AndRaise(Exception('unhandled error'))
     self.store.increment_attempts('1234')
     self.store.set_timestamp('1234', IsA(float))
     self.mox.ReplayAll()
     def backoff(envelope, attempts):
         return 0
     queue = Queue(self.store, self.relay, backoff=backoff, relay_pool=5)
     queue.enqueue(self.env)
     queue.relay_pool.join()
 def test_enqueue_wait_unhandledfail(self):
     self.store.write(self.env, IsA(float)).AndReturn('1234')
     self.relay._attempt(self.env, 0).AndRaise(Exception('unhandled error'))
     self.store.increment_attempts('1234')
     self.store.set_timestamp('1234', IsA(float))
     self.mox.ReplayAll()
     def backoff(envelope, attempts):
         return 0
     queue = Queue(self.store, self.relay, backoff=backoff, relay_pool=5)
     queue.enqueue(self.env)
     queue.relay_pool.join()
 def test_enqueue_wait_transientfail(self):
     self.store.write(self.env, IsA(float)).AndReturn('1234')
     self.relay._attempt(self.env, 0).AndRaise(TransientRelayError('transient', Reply('450', 'transient')))
     self.store.increment_attempts('1234')
     self.store.set_timestamp('1234', IsA(float))
     self.mox.ReplayAll()
     def backoff(envelope, attempts):
         return 0
     queue = Queue(self.store, self.relay, backoff=backoff, relay_pool=5)
     queue.enqueue(self.env)
     queue.relay_pool.join()
 def test_enqueue_wait_splitpolicy(self):
     splitpolicy1 = self.mox.CreateMock(QueuePolicy)
     splitpolicy2 = self.mox.CreateMock(QueuePolicy)
     regpolicy = self.mox.CreateMock(QueuePolicy)
     env1 = Envelope('*****@*****.**', ['*****@*****.**'])
     env2 = Envelope('*****@*****.**', ['*****@*****.**'])
     env3 = Envelope('*****@*****.**', ['*****@*****.**'])
     splitpolicy1.apply(self.env).AndReturn([env1, env2])
     regpolicy.apply(env1)
     splitpolicy2.apply(env1)
     regpolicy.apply(env2)
     splitpolicy2.apply(env2).AndReturn([env2, env3])
     self.store.write(env1, IsA(float)).AndReturn('1234')
     self.store.write(env2, IsA(float)).AndReturn('5678')
     self.store.write(env3, IsA(float)).AndReturn('90AB')
     self.relay._attempt(env1, 0).InAnyOrder('relay')
     self.relay._attempt(env2, 0).InAnyOrder('relay')
     self.relay._attempt(env3, 0).InAnyOrder('relay')
     self.store.remove('1234').InAnyOrder('relay')
     self.store.remove('5678').InAnyOrder('relay')
     self.store.remove('90AB').InAnyOrder('relay')
     self.mox.ReplayAll()
     queue = Queue(self.store, self.relay, relay_pool=5)
     queue.add_policy(splitpolicy1)
     queue.add_policy(regpolicy)
     queue.add_policy(splitpolicy2)
     self.assertEqual([(env1, '1234'), (env2, '5678'), (env3, '90AB')],
                      queue.enqueue(self.env))
     queue.relay_pool.join()
Example #10
0
 def test_enqueue_wait_splitpolicy(self):
     splitpolicy1 = self.mox.CreateMock(QueuePolicy)
     splitpolicy2 = self.mox.CreateMock(QueuePolicy)
     regpolicy = self.mox.CreateMock(QueuePolicy)
     env1 = Envelope('*****@*****.**', ['*****@*****.**'])
     env2 = Envelope('*****@*****.**', ['*****@*****.**'])
     env3 = Envelope('*****@*****.**', ['*****@*****.**'])
     splitpolicy1.apply(self.env).AndReturn([env1, env2])
     regpolicy.apply(env1)
     splitpolicy2.apply(env1)
     regpolicy.apply(env2)
     splitpolicy2.apply(env2).AndReturn([env2, env3])
     self.store.write(env1, IsA(float)).AndReturn('1234')
     self.store.write(env2, IsA(float)).AndReturn('5678')
     self.store.write(env3, IsA(float)).AndReturn('90AB')
     self.relay._attempt(env1, 0).InAnyOrder('relay')
     self.relay._attempt(env2, 0).InAnyOrder('relay')
     self.relay._attempt(env3, 0).InAnyOrder('relay')
     self.store.remove('1234').InAnyOrder('relay')
     self.store.remove('5678').InAnyOrder('relay')
     self.store.remove('90AB').InAnyOrder('relay')
     self.mox.ReplayAll()
     queue = Queue(self.store, self.relay, relay_pool=5)
     queue.add_policy(splitpolicy1)
     queue.add_policy(regpolicy)
     queue.add_policy(splitpolicy2)
     self.assertEqual([(env1, '1234'), (env2, '5678'), (env3, '90AB')],
                      queue.enqueue(self.env))
     queue.relay_pool.join()
 def test_enqueue_wait(self):
     self.store.write(self.env, IsA(float)).AndReturn('1234')
     self.relay._attempt(self.env, 0)
     self.store.remove('1234')
     self.mox.ReplayAll()
     queue = Queue(self.store, self.relay, relay_pool=5)
     self.assertEqual([(self.env, '1234')], queue.enqueue(self.env))
     queue.relay_pool.join()
Example #12
0
 def test_enqueue_wait(self):
     self.store.write(self.env, IsA(float)).AndReturn('1234')
     self.relay._attempt(self.env, 0)
     self.store.remove('1234')
     self.mox.ReplayAll()
     queue = Queue(self.store, self.relay, relay_pool=5)
     self.assertEqual([(self.env, '1234')], queue.enqueue(self.env))
     queue.relay_pool.join()
Example #13
0
 def test_enqueue_wait_partial_relay_expired(self):
     env = Envelope('*****@*****.**', ['*****@*****.**',
                                           '*****@*****.**',
                                           '*****@*****.**'])
     bounce_mock = self.mox.CreateMockAnything()
     bounce_mock(IsA(Envelope), IsA(Reply)).AndReturn(None)
     bounce_mock(IsA(Envelope), IsA(Reply)).AndReturn(None)
     self.store.write(env, IsA(float)).AndReturn('1234')
     self.relay._attempt(env, 0).AndReturn([TransientRelayError('transient', Reply('450', 'transient 1')),
                                            TransientRelayError('transient', Reply('450', 'transient 1')),
                                            TransientRelayError('transient', Reply('450', 'transient 2'))])
     self.store.increment_attempts('1234')
     self.store.remove('1234')
     self.mox.ReplayAll()
     queue = Queue(self.store, self.relay, bounce_factory=bounce_mock, relay_pool=5)
     queue.enqueue(env)
     queue.relay_pool.join()
Example #14
0
 def test_enqueue_wait_partial_relay(self):
     env = Envelope('*****@*****.**', ['*****@*****.**',
                                           '*****@*****.**',
                                           '*****@*****.**'])
     self.store.write(env, IsA(float)).AndReturn('1234')
     self.relay._attempt(env, 0).AndReturn([None,
                                            TransientRelayError('transient', Reply('450', 'transient')),
                                            PermanentRelayError('permanent', Reply('550', 'permanent'))])
     self.store.increment_attempts('1234')
     self.store.set_timestamp('1234', IsA(float))
     self.store.set_recipients_delivered('1234', [0, 2])
     self.mox.ReplayAll()
     def backoff(envelope, attempts):
         return 0
     def no_bounce(envelope, reply):
         return None
     queue = Queue(self.store, self.relay, backoff=backoff, bounce_factory=no_bounce, relay_pool=5)
     queue.enqueue(env)
     queue.relay_pool.join()
 def test_enqueue_wait_norelay(self):
     self.store.write(self.env, IsA(float)).AndReturn('1234')
     self.mox.ReplayAll()
     queue = Queue(self.store, relay_pool=5)
     assert_equal([(self.env, '1234')], queue.enqueue(self.env))
     queue.relay_pool.join()
Example #16
0
 def test_enqueue_wait_norelay(self):
     self.store.write(self.env, IsA(float)).AndReturn('1234')
     self.mox.ReplayAll()
     queue = Queue(self.store, relay_pool=5)
     assert_equal([(self.env, '1234')], queue.enqueue(self.env))
     queue.relay_pool.join()