def test_retry_connect(self):
        self.connected_count = 0
        self.disconnected_count = 0

        def check_connected(client):
            self.connected_count += 1
            self.failUnlessEqual(self.client, client)
            self.failUnless(self.client.protocol)
            return self.client.put("tube", 1).addCallbacks(
                lambda res: self.failUnlessEqual('ok', res['state']),
                self.fail)

        def check_disconnected(failure):
            self.disconnected_count += 1
            client, reason = failure.value
            self.failUnlessIsInstance(reason,
                                      (ConnectionDone, ConnectionRefusedError))
            self.failIf(self.client.protocol)

        def check_count(_):
            self.failUnlessEqual(1, self.connected_count)
            self.failUnlessEqual(1, self.disconnected_count)

        spawner.terminate_all()
        return self.client.connectTCP(self.host, self.port).addCallbacks(self.fail, check_disconnected) \
                   .addCallback(lambda _: _setUp(self)).addCallback(lambda _: self.client.deferred).addCallbacks(check_connected, self.fail) \
                   .addCallback(check_count)
        def restart_beanstalkd(_):
            def put():
                def mark(_):
                    self.callbacked = True

                self.client.put("JOB").addCallback(mark)
                return self.client.deferred

            def start(_):
                _setUp(self)
                return self.client.deferred

            spawner.terminate_all()
            return put().addCallbacks(
                self.fail, start)  # put job before we knew about disconnect
Esempio n. 3
0
def teardown():
    spawner.terminate_all()
 def tearDown(self):
     if self.client.protocol:
         d = self.client.disconnect()
     else:
         d = defer.fail("Not connected")
     return d.addCallbacks(self.fail, lambda _: spawner.terminate_all())
 def tearDown(self):
     spawner.terminate_all()
 def check(proto):
     spawner.terminate_all()
     return proto.put("JOB").addCallbacks(
         self.fail, lambda fail: fail.trap(
             'twisted.internet.error.ConnectionClosed'))
Esempio n. 7
0
def teardown():
    spawner.terminate_all()