Ejemplo n.º 1
0
 def test_context(self):
     t = Timer()
     t = t.__enter__()
     self.assertTrue(t.started > 0)
     self.assertEqual(t.stopped, 0)
     t.__exit__()
     self.assertTrue(t.stopped > 0)
Ejemplo n.º 2
0
 def test_stop(self, _time):
     _time.return_value = 20.0
     t = Timer()
     t.started = 10.0
     t.stop()
     self.assertEqual(t.started, 10.0)
     self.assertEqual(t.stopped, 20.0)
Ejemplo n.º 3
0
 def test_context(self):
     t = Timer()
     t = t.__enter__()
     self.assertTrue(t.started > 0)
     self.assertEqual(t.stopped, 0)
     t.__exit__()
     self.assertTrue(t.stopped > 0)
Ejemplo n.º 4
0
 def test_stop(self, _time):
     _time.return_value = 20.0
     t = Timer()
     t.started = 10.0
     t.stop()
     self.assertEqual(t.started, 10.0)
     self.assertEqual(t.stopped, 20.0)
Ejemplo n.º 5
0
 def test_A(self):
     env = TestEnv()
     self.populate(env)
     manager = managers.consumer_applicability_manager()
     units = [TEST_UNIT,]
     criteria = self.criteria()
     print 'Testing applicability ....'
     timer = Timer()
     timer.start()
     applicable = manager.units_applicable(criteria, units)
     timer.stop()
     print 'Finished: [%s] in: %s' % (env, timer)
     for id, report in applicable.items():
         self.assertTrue(report[0].applicable)
Ejemplo n.º 6
0
def demoperftest(uuid, n=50):
    benchmarks = []
    print "measuring performance using demo() ..."
    agent = Agent(uuid)
    timer = Timer()
    for i in range(0, n):
        timer.start()
        demo(agent)
        timer.stop()
        benchmarks.append(str(timer))
        print "========= DEMO:%d [%s] ========" % (i, timer)
    print "benchmarks:"
    for t in benchmarks:
        print t
    del agent
    sys.exit(0)
Ejemplo n.º 7
0
 def send_reply(self, request, result):
     """
     Send the reply if requested.
     :param request: The received request.
     :type request: Document
     :param result: The request result.
     :type result: object
     """
     sn = request.sn
     data = request.data
     ts = request.ts
     now = time()
     duration = Timer(ts, now)
     address = request.replyto
     log.info('Request: %s processed in: %s', sn, duration)
     if not address:
         return
     try:
         self.producer.send(address,
                            sn=sn,
                            data=data,
                            result=result,
                            timestamp=timestamp())
     except Exception:
         log.exception('Send: reply, failed: %s', result)
Ejemplo n.º 8
0
 def __getreply(self, sn, reader):
     """
     Get the reply matched by serial number.
     @param sn: The request serial number.
     @type sn: str
     @param reader: A reader.
     @type reader: L{Reader}
     @return: The matched reply envelope.
     @rtype: L{Envelope}
     """
     timer = Timer()
     timeout = float(self.timeout[1])
     while True:
         timer.start()
         envelope = reader.search(sn, int(timeout))
         if envelope:
             reader.ack()
         timer.stop()
         elapsed = timer.duration()
         if elapsed > timeout:
             raise RequestTimeout(sn, 1)
         else:
             timeout -= elapsed
         if envelope:
             if envelope.status == 'progress':
                 self.__onprogress(envelope)
             else:
                 return self.__onreply(envelope)
         else:
             raise RequestTimeout(sn, 1)
Ejemplo n.º 9
0
 def test_str(self):
     t = Timer()
     # not started
     self.assertEqual(str(t), 'not-running')
     # started but not stopped
     t.started = 1
     self.assertEqual(str(t), 'started: %d (running)' % t.started)
     # milliseconds
     t.started = 0.10
     t.stopped = 0.25
     self.assertEqual(str(t), '150 (ms)')
     # seconds
     t.started = 10.0
     t.stopped = 25.0
     self.assertEqual(str(t), '15.000 (seconds)')
     # minutes
     t.started = 10.0
     t.stopped = 100.0
     self.assertEqual(str(t), '1.500 (minutes)')
Ejemplo n.º 10
0
 def test_unicode(self):
     t = Timer()
     # not started
     self.assertEqual(unicode(t), 'idle')
     # started but not stopped
     t.started = 1
     self.assertEqual(unicode(t), 'started')
     # milliseconds
     t.started = 0.10
     t.stopped = 0.25
     self.assertEqual(unicode(t), '150 (ms)')
     # seconds
     t.started = 10.0
     t.stopped = 25.0
     self.assertEqual(unicode(t), '15.000 (seconds)')
     # minutes
     t.started = 10.0
     t.stopped = 100.0
     self.assertEqual(unicode(t), '1.500 (minutes)')
Ejemplo n.º 11
0
def test_memory():
    N = 10000
    with open(__file__) as fp:
        content = fp.read()
    agent = Agent(data=content)
    dog = agent.Dog()
    t = Timer()
    t.start()
    print('testing memory ...')
    for n in range(0, N):
        dog.bark('hello!')
        print('tested {}'.format(n))
    t.stop()
    print('total={}, percall={} (ms)'.format(t, (t.duration() / N) * 1000))
    sys.exit(0)
Ejemplo n.º 12
0
 def test_unicode(self):
     t = Timer()
     # not started
     self.assertEqual(unicode(t), 'not-running')
     # started but not stopped
     t.started = 1
     self.assertEqual(unicode(t), 'started: %d (running)' % t.started)
     # milliseconds
     t.started = 0.10
     t.stopped = 0.25
     self.assertEqual(unicode(t), '150 (ms)')
     # seconds
     t.started = 10.0
     t.stopped = 25.0
     self.assertEqual(unicode(t), '15.000 (seconds)')
     # minutes
     t.started = 10.0
     t.stopped = 100.0
     self.assertEqual(unicode(t), '1.500 (minutes)')
Ejemplo n.º 13
0
 def test_str(self):
     t = Timer()
     # not started
     self.assertEqual(str(t), 'idle')
     # started but not stopped
     t.started = 1
     self.assertEqual(str(t), 'started')
     # milliseconds
     t.started = 0.10
     t.stopped = 0.25
     self.assertEqual(str(t), '150 (ms)')
     # seconds
     t.started = 10.0
     t.stopped = 25.0
     self.assertEqual(str(t), '15.000 (seconds)')
     # minutes
     t.started = 10.0
     t.stopped = 100.0
     self.assertEqual(str(t), '1.500 (minutes)')
Ejemplo n.º 14
0
def test_memory():
    N = 10000
    with open(__file__) as fp:
        content = fp.read()
    agent = Agent(data=content)
    dog = agent.Dog()
    t = Timer()
    t.start()
    print 'testing memory ...'
    for n in range(0, N):
        dog.bark('hello!')
        print 'tested %d' % n
    t.stop()
    print 'total=%s, percall=%f (ms)' % (t, (t.duration()/N)*1000)
    sys.exit(0)
Ejemplo n.º 15
0
def test_duplex(pool, fn):
    N = 100
    print 'START'
    t = Timer()
    t.start()
    reader = ReplyReader(pool, N)
    reader.start()
    for i in range(0,N):
        request = 'REQUEST-%d' % i
        pool.run(fn, request)
    reader.join()
    t.stop()
    for r in reader.reply:
        print r
    print 'total: %s, per-call: %f' % (t, t.duration()/N)
    print repr(pool)
Ejemplo n.º 16
0
    def get_reply(self, sn, reader):
        """
        Get the reply matched by serial number.
        :param sn: The request serial number.
        :type sn: str
        :param reader: A reader.
        :type reader: gofer.messaging.consumer.Reader
        :return: The matched reply document.
        :rtype: Document
        """
        timer = Timer()
        timeout = float(self.wait)

        while not Thread.aborted():
            timer.start()
            document = reader.search(sn, int(timeout))
            timer.stop()
            elapsed = timer.duration()
            if elapsed > timeout:
                raise RequestTimeout(sn, self.wait)
            else:
                timeout -= elapsed

            if not document:
                raise RequestTimeout(sn, self.wait)

            # rejected
            if document.status == 'rejected':
                raise DocumentError(document.code, document.description,
                                    document.document, document.details)

            # accepted | started
            if document.status in ('accepted', 'started'):
                continue

            # progress reported
            if document.status == 'progress':
                self.on_progress(document)
                continue

            # reply
            return self.on_reply(document)
Ejemplo n.º 17
0
    def get_reply(self, sn, reader):
        """
        Get the reply matched by serial number.
        :param sn: The request serial number.
        :type sn: str
        :param reader: A reader.
        :type reader: gofer.messaging.consumer.Reader
        :return: The matched reply document.
        :rtype: Document
        """
        timer = Timer()
        timeout = float(self.wait)

        while not Thread.aborted():
            timer.start()
            document = reader.search(sn, int(timeout))
            timer.stop()
            elapsed = timer.duration()
            if elapsed > timeout:
                raise RequestTimeout(sn, self.wait)
            else:
                timeout -= elapsed

            if not document:
                raise RequestTimeout(sn, self.wait)

            # rejected
            if document.status == 'rejected':
                raise DocumentError(
                    document.code,
                    document.description,
                    document.document,
                    document.details)

            # accepted | started
            if document.status in ('accepted', 'started'):
                continue

            # progress reported
            if document.status == 'progress':
                self.on_progress(document)
                continue

            # reply
            return self.on_reply(document)
Ejemplo n.º 18
0
 def test_duration(self):
     t = Timer()
     t.started = 10.0
     t.stopped = 100.0
     self.assertEqual(t.duration(), 90.0)
Ejemplo n.º 19
0
def test_performance():
    N = 200
    agent = Agent()
    dog = agent.Dog()
    t = Timer()
    t.start()
    print 'measuring performance ...'
    for i in range(0, N):
        dog.bark('performance!')
    t.stop()
    print 'total=%s, percall=%f (ms)' % (t, (t.duration()/N)*1000)
    #sys.exit(0)
    # ASYNCHRONOUS
    agent = Agent(wait=0)
    dog = agent.Dog()
    t = Timer()
    t.start()
    print 'measuring (async) performance ...'
    for i in range(0, N):
        dog.bark('performance!')
    t.stop()
    print 'total=%s, percall=%f (ms)' % (t, (t.duration()/N)*1000)
    sys.exit(0)
Ejemplo n.º 20
0
 def duration(self):
     t = Timer()
     t.started = 10.0
     t.stopped = 100.0
     self.assertEqual(t.duration(), 90.0)
Ejemplo n.º 21
0
 def test_init(self):
     t = Timer()
     self.assertEqual(t.started, 0)
     self.assertEqual(t.stopped, 0)
Ejemplo n.º 22
0
def test_performance():
    N = 200
    agent = Agent()
    dog = agent.Dog()
    t = Timer()
    t.start()
    print('measuring performance ...')
    for i in range(0, N):
        dog.bark('performance!')
    t.stop()
    print('total={}, percall={} (ms)'.format(t, (t.duration() / N) * 1000))
    # sys.exit(0)
    # ASYNCHRONOUS
    agent = Agent(wait=0)
    dog = agent.Dog()
    t = Timer()
    t.start()
    print('measuring (async) performance ...')
    for i in range(0, N):
        dog.bark('performance!')
    t.stop()
    print('total={}, percall={} (ms)'.format(t, (t.duration() / N) * 1000))
    sys.exit(0)
Ejemplo n.º 23
0
def perftest(uuid):
    N = 200
    agent = Agent(uuid)
    dog = agent.Dog()
    t = Timer()
    t.start()
    print "measuring performance ..."
    for i in range(0, N):
        dog.bark("performance!")
    t.stop()
    print "total=%s, percall=%f (ms)" % (t, (t.duration() / N) * 1000)
    # sys.exit(0)
    # ASYNCHRONOUS
    dog = agent.Dog(async=1)
    t = Timer()
    t.start()
    print "measuring (async) performance ..."
    for i in range(0, N):
        dog.bark("performance!")
    t.stop()
    print "total=%s, percall=%f (ms)" % (t, (t.duration() / N) * 1000)
    sys.exit(0)