예제 #1
0
 def test_timeout_fails(self):
     d = misc.cancelAfter(10, self.d, self.reactor)
     self.assertFalse(d.called)
     self.reactor.advance(11)
     self.d.errback(RuntimeError("oh noes"))  # ignored
     self.assertTrue(d.called)
     yield self.assertFailure(d, defer.CancelledError)
예제 #2
0
 def test_timeout_succeeds(self):
     d = misc.cancelAfter(10, self.d, self.reactor)
     self.assertFalse(d.called)
     self.reactor.advance(11)
     d.callback("result")  # ignored
     self.assertTrue(d.called)
     yield self.assertFailure(d, defer.CancelledError)
예제 #3
0
파일: manager.py 프로젝트: Geeglee/buildbot
    def newConnection(self, conn, buildslaveName):
        if buildslaveName in self.connections:
            log.msg("Got duplication connection from '%s'" " starting arbitration procedure" % buildslaveName)
            old_conn = self.connections[buildslaveName]
            try:
                yield misc.cancelAfter(self.PING_TIMEOUT, old_conn.remotePrint("master got a duplicate connection"))
                # if we get here then old connection is still alive, and new
                # should be rejected
                defer.returnValue(Failure(RuntimeError("rejecting duplicate slave")))
            except defer.CancelledError:
                old_conn.loseConnection()
                log.msg("Connected slave '%s' ping timed out after %d seconds" % (buildslaveName, self.PING_TIMEOUT))
            except Exception as e:
                old_conn.loseConnection()
                log.msg("Got error while trying to ping connected slave %s:" "%s" % (buildslaveName, e))
            log.msg("Old connection for '%s' was lost, accepting new" % buildslaveName)

        try:
            yield conn.remotePrint(message="attached")
            info = yield conn.remoteGetSlaveInfo()
            log.msg("Got slaveinfo from '%s'" % buildslaveName)
        except Exception as e:
            log.msg("Failed to communicate with slave '%s'\n" "%s" % (buildslaveName, e))
            defer.returnValue(False)

        conn.info = info
        self.connections[buildslaveName] = conn

        def remove():
            del self.connections[buildslaveName]

        conn.notifyOnDisconnect(remove)

        # accept the connection
        defer.returnValue(True)
예제 #4
0
 def test_timeout_fails(self):
     d = misc.cancelAfter(10, self.d, self.reactor)
     self.assertFalse(d.called)
     self.reactor.advance(11)
     self.d.errback(RuntimeError("oh noes"))  # ignored
     self.assertTrue(d.called)
     yield self.assertFailure(d, defer.CancelledError)
예제 #5
0
 def test_timeout_succeeds(self):
     d = misc.cancelAfter(10, self.d, self.reactor)
     self.assertFalse(d.called)
     self.reactor.advance(11)
     d.callback("result")  # ignored
     self.assertTrue(d.called)
     yield self.assertFailure(d, defer.CancelledError)
예제 #6
0
 def test_timeout_fails(self):
     c = task.Clock()
     d = misc.cancelAfter(10, self.d, _reactor=c)
     self.assertFalse(d.called)
     c.advance(11)
     self.d.errback(RuntimeError("oh noes"))  # ignored
     self.assertTrue(d.called)
     self.assertFailure(d, defer.CancelledError)
예제 #7
0
 def test_timeout_succeeds(self):
     c = task.Clock()
     d = misc.cancelAfter(10, self.d, _reactor=c)
     self.assertFalse(d.called)
     c.advance(11)
     d.callback("result")  # ignored
     self.assertTrue(d.called)
     self.assertFailure(d, defer.CancelledError)
예제 #8
0
 def test_timeout_fails(self):
     c = task.Clock()
     d = misc.cancelAfter(10, self.d, _reactor=c)
     self.assertFalse(d.called)
     c.advance(11)
     self.d.errback(RuntimeError("oh noes"))  # ignored
     self.assertTrue(d.called)
     self.assertFailure(d, defer.CancelledError)
예제 #9
0
 def test_timeout_succeeds(self):
     c = task.Clock()
     d = misc.cancelAfter(10, self.d, _reactor=c)
     self.assertFalse(d.called)
     c.advance(11)
     d.callback("result")  # ignored
     self.assertTrue(d.called)
     self.assertFailure(d, defer.CancelledError)
예제 #10
0
    def test_succeeds(self):
        d = misc.cancelAfter(10, self.d)
        self.assertIdentical(d, self.d)

        @d.addCallback
        def check(r):
            self.assertEqual(r, "result")
        self.assertFalse(d.called)
        self.d.callback("result")
        self.assertTrue(d.called)
예제 #11
0
    def test_succeeds(self):
        d = misc.cancelAfter(10, self.d)
        self.assertIdentical(d, self.d)

        @d.addCallback
        def check(r):
            self.assertEqual(r, "result")
        self.assertFalse(d.called)
        self.d.callback("result")
        self.assertTrue(d.called)
예제 #12
0
파일: manager.py 프로젝트: BME-IK/buildbot
 def newConnection(self, conn, buildslaveName):
     if buildslaveName in self.connections:
         log.msg("Got duplication connection from '%s'" " starting arbitration procedure" % buildslaveName)
         old_conn = self.connections[buildslaveName]
         try:
             yield misc.cancelAfter(self.PING_TIMEOUT, old_conn.remotePrint("master got a duplicate connection"))
             # if we get here then old connection is still alive, and new
             # should be rejected
             defer.returnValue(Failure(RuntimeError("rejecting duplicate slave")))
         except defer.CancelledError:
             old_conn.loseConnection()
             log.msg("Connected slave '%s' ping timed out after %d seconds" % (buildslaveName, self.PING_TIMEOUT))
         except Exception, e:
             old_conn.loseConnection()
             log.msg("Got error while trying to ping connected slave %s:" "%s" % (buildslaveName, e))
         log.msg("Old connection for '%s' was lost, accepting new" % buildslaveName)
예제 #13
0
    def newConnection(self, conn, workerName):
        if workerName in self.connections:
            log.msg(f"Got duplication connection from '{workerName}'"
                    " starting arbitration procedure")
            old_conn = self.connections[workerName]
            try:
                yield misc.cancelAfter(
                    self.PING_TIMEOUT,
                    old_conn.remotePrint("master got a duplicate connection"),
                    self.master.reactor)
                # if we get here then old connection is still alive, and new
                # should be rejected
                raise RuntimeError("rejecting duplicate worker")
            except defer.CancelledError:
                old_conn.loseConnection()
                log.msg(
                    f"Connected worker '{workerName}' ping timed out after {self.PING_TIMEOUT} "
                    "seconds")
            except RuntimeError:
                raise
            except Exception as e:
                old_conn.loseConnection()
                log.msg(
                    f"Got error while trying to ping connected worker {workerName}:{e}"
                )
            log.msg(
                f"Old connection for '{workerName}' was lost, accepting new")

        try:
            yield conn.remotePrint(message="attached")
            info = yield conn.remoteGetWorkerInfo()
            log.msg(f"Got workerinfo from '{workerName}'")
        except Exception as e:
            log.msg(f"Failed to communicate with worker '{workerName}'\n{e}".
                    format(workerName, e))
            raise

        conn.info = info
        self.connections[workerName] = conn

        def remove():
            del self.connections[workerName]

        conn.notifyOnDisconnect(remove)

        # accept the connection
        return True
예제 #14
0
    def newConnection(self, conn, workerName):
        if workerName in self.connections:
            log.msg("Got duplication connection from '%s'"
                    " starting arbitration procedure" % workerName)
            old_conn = self.connections[workerName]
            try:
                yield misc.cancelAfter(
                    self.PING_TIMEOUT,
                    old_conn.remotePrint("master got a duplicate connection"))
                # if we get here then old connection is still alive, and new
                # should be rejected
                defer.returnValue(
                    Failure(RuntimeError("rejecting duplicate worker")))
            except defer.CancelledError:
                old_conn.loseConnection()
                log.msg(
                    "Connected worker '%s' ping timed out after %d seconds" %
                    (workerName, self.PING_TIMEOUT))
            except Exception as e:
                old_conn.loseConnection()
                log.msg("Got error while trying to ping connected worker %s:"
                        "%s" % (workerName, e))
            log.msg("Old connection for '%s' was lost, accepting new" %
                    workerName)

        try:
            yield conn.remotePrint(message="attached")
            info = yield conn.remoteGetWorkerInfo()
            log.msg("Got workerinfo from '%s'" % workerName)
        except Exception as e:
            log.msg("Failed to communicate with worker '%s'\n"
                    "%s" % (workerName, e))
            defer.returnValue(False)

        conn.info = info
        self.connections[workerName] = conn

        def remove():
            del self.connections[workerName]

        conn.notifyOnDisconnect(remove)

        # accept the connection
        defer.returnValue(True)
예제 #15
0
파일: manager.py 프로젝트: zozo123/buildbot
 def newConnection(self, conn, buildslaveName):
     if buildslaveName in self.connections:
         log.msg("Got duplication connection from '%s'"
                 " starting arbitration procedure" % buildslaveName)
         old_conn = self.connections[buildslaveName]
         try:
             yield misc.cancelAfter(self.PING_TIMEOUT,
                                    old_conn.remotePrint("master got a duplicate connection"))
             # if we get here then old connection is still alive, and new
             # should be rejected
             defer.returnValue(
                 Failure(RuntimeError("rejecting duplicate slave"))
             )
         except defer.CancelledError:
             old_conn.loseConnection()
             log.msg("Connected slave '%s' ping timed out after %d seconds"
                     % (buildslaveName, self.PING_TIMEOUT))
         except Exception, e:
             old_conn.loseConnection()
             log.msg("Got error while trying to ping connected slave %s:"
                     "%s" % (buildslaveName, e))
         log.msg("Old connection for '%s' was lost, accepting new" % buildslaveName)
예제 #16
0
 def test_fails(self):
     d = misc.cancelAfter(10, self.d)
     self.assertFalse(d.called)
     self.d.errback(RuntimeError("oh noes"))
     self.assertTrue(d.called)
     yield self.assertFailure(d, RuntimeError)
예제 #17
0
 def test_fails(self):
     d = misc.cancelAfter(10, self.d)
     self.assertFalse(d.called)
     self.d.errback(RuntimeError("oh noes"))
     self.assertTrue(d.called)
     self.assertFailure(d, RuntimeError)