Ejemplo n.º 1
0
    def mkAPI(self):
        # We can't reliably put the socket inside the _trial_temp working
        # directory because that tends to be longer than 108 bytes, /tmp works
        self.tmpdir = tempfile.mkdtemp(prefix="rrdcached.test.", dir="/tmp")
        sock = os.path.join(self.tmpdir, "rrdcached.sock")
        pidfile = os.path.join(self.tmpdir, "rrdcached.pid")
        self.server = RealCacheServer(sock, pidfile)

        def client_fail(result):
            print "Client fail: %s" % result
            os.system("ps ax | grep rrdcached")
            d = self.server.stopListening()
            d.addBoth(lambda x: result)
            return d

        def client(result):
            api = twist.RRDTwistedAPI()
            deferred = api.open(sock)
            deferred.addCallback(lambda x: api)
            deferred.addErrback(client_fail)
            return deferred

        deferred = self.server.startListening()
        deferred.addCallback(client)
        deferred.addErrback(self.rmtmpdir)
        return deferred
Ejemplo n.º 2
0
class TwistCacheTestTestCase(TwistCacheFakedTestCase):
    # FIXME: This is copied from test_api, if this code is ever changed it
    # should be re-organized to kill the copy but it works right now so meh

    def mkAPI(self):
        # We can't reliably put the socket inside the _trial_temp working
        # directory because that tends to be longer than 108 bytes, /tmp works
        self.tmpdir = tempfile.mkdtemp(prefix="rrdcached.test.", dir="/tmp")
        sock = os.path.join(self.tmpdir, "rrdcached.sock")
        pidfile = os.path.join(self.tmpdir, "rrdcached.pid")
        self.server = RealCacheServer(sock, pidfile)

        def client_fail(result):
            print "Client fail: %s" % result
            os.system("ps ax | grep rrdcached")
            d = self.server.stopListening()
            d.addBoth(lambda x: result)
            return d

        def client(result):
            api = twist.RRDTwistedAPI()
            deferred = api.open(sock)
            deferred.addCallback(lambda x: api)
            deferred.addErrback(client_fail)
            return deferred

        deferred = self.server.startListening()
        deferred.addCallback(client)
        deferred.addErrback(self.rmtmpdir)
        return deferred

    def rmtmpdir(self, result):
        shutil.rmtree(self.tmpdir)
        return result

    def tearDown(self):
        d = self.api.close()
        d.addBoth(lambda x: self.server.stopListening())
        d.addBoth(self.rmtmpdir)
        return d