Beispiel #1
0
    def checkStats(self, metricName, mn, mx):
        """Check that stats are computed correctly from the database"""
        engine = repository.engineFactory(config=self.__config)
        with engine.begin() as conn:
            metricObj = (repository.getCustomMetricByName(
                conn,
                metricName,
                fields=[schema.metric.c.uid, schema.metric.c.parameters]))
            stats = repository.getMetricStats(conn, metricObj.uid)

        self.assertSetEqual(set(stats.keys()), set(("min", "max")))
        self.assertAlmostEqual(stats["min"], mn)
        self.assertAlmostEqual(stats["max"], mx)
  def checkStats(self, metricName, mn, mx):
    """Check that stats are computed correctly from the database"""
    engine = repository.engineFactory(config=self.__config)
    with engine.begin() as conn:
      metricObj = (
        repository.getCustomMetricByName(conn,
                                         metricName,
                                         fields=[schema.metric.c.uid,
                                                 schema.metric.c.parameters]))
      stats = repository.getMetricStats(conn, metricObj.uid)

    self.assertSetEqual(set(stats.keys()), set(("min", "max")))
    self.assertAlmostEqual(stats["min"], mn)
    self.assertAlmostEqual(stats["max"], mx)
Beispiel #3
0
    def testStats(self):
        """Tests that stats are computed correctly."""
        metricName = "testStats.%i" % int(time.time())
        LOGGER.info("Running test with metric name: %s", metricName)

        self.addCleanup(self._deleteMetric, metricName)

        # Add custom metric data
        sock = socket.socket()
        sock.connect(("localhost", self.plaintextPort))
        sock.sendall("%s 5.0 1386201600\n" % metricName)
        sock.sendall("%s 6.0 1386288000\n" % metricName)
        sock.sendall("%s 7.0 1386374400\n" % metricName)
        self.gracefullyCloseSocket(sock)

        time.sleep(5)
        for _attempt in xrange(6):
            try:
                uid = self.checkMetricCreated(metricName, numRecords=3)
                LOGGER.info("Metric %s has uid: %s", metricName, uid)
                break
            except:
                time.sleep(10)
        else:
            self.fail("Metric not created within a reasonable amount of time.")

        # Check that stats are computed correctly from the database
        for _attempt in xrange(6):
            try:
                with repository.engineFactory(self.config).connect() as conn:
                    stats = repository.getMetricStats(conn, uid)
                self.assertSetEqual(set(stats.keys()), set(("min", "max")))
                self.assertAlmostEqual(stats["min"], 5.0)
                self.assertAlmostEqual(stats["max"], 7.0)
                break
            except MetricStatisticsNotReadyError:
                time.sleep(10)
        else:
            self.fail(
                "Metric created, but statistics not ready within a reasonable"
                " amount of time.")
  def testStats(self):
    """Tests that stats are computed correctly."""
    metricName = "testStats.%i" % int(time.time())
    LOGGER.info("Running test with metric name: %s", metricName)

    self.addCleanup(self._deleteMetric, metricName)

    # Add custom metric data
    sock = socket.socket()
    sock.connect(("localhost", self.plaintextPort))
    sock.sendall("%s 5.0 1386201600\n" % metricName)
    sock.sendall("%s 6.0 1386288000\n" % metricName)
    sock.sendall("%s 7.0 1386374400\n" % metricName)
    self.gracefullyCloseSocket(sock)

    time.sleep(5)
    for _attempt in xrange(6):
      try:
        uid = self.checkMetricCreated(metricName, numRecords=3)
        LOGGER.info("Metric %s has uid: %s", metricName, uid)
        break
      except:
        time.sleep(10)
    else:
      self.fail("Metric not created within a reasonable amount of time.")

    # Check that stats are computed correctly from the database
    for _attempt in xrange(6):
      try:
        with repository.engineFactory(self.config).connect() as conn:
          stats = repository.getMetricStats(conn, uid)
        self.assertSetEqual(set(stats.keys()), set(("min", "max")))
        self.assertAlmostEqual(stats["min"], 5.0)
        self.assertAlmostEqual(stats["max"], 7.0)
        break
      except MetricStatisticsNotReadyError:
        time.sleep(10)
    else:
      self.fail("Metric created, but statistics not ready within a reasonable"
                " amount of time.")