def test_1(self): obj = self.obj mock = MockReader() mock.data.append((1, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((2, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((2, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((3, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((3, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((4, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((4, "", 1, r(), r(), r(), 200, None, '')) obj.add_listener(mock) for point in mock.datapoints(): self.assertNotEquals( 0, point[DataPoint.CUMULATIVE][''][KPISet.CONCURRENCY]) mock.data.append((2, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((2, "", 1, r(), r(), r(), 200, None, '')) for point in mock.datapoints(): pass for point in mock.datapoints(True): pass for point in mock.results: overall = point[DataPoint.CURRENT][''] self.assertTrue(len(overall[KPISet.PERCENTILES]) > 0)
def test_json(self): obj = self.obj mock = MockReader() mock.buffer_scale_idx = '100.0' mock.data.append((1, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((2, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((2, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((3, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((3, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((4, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((4, "", 1, r(), r(), r(), 200, None, '', 0)) obj.add_listener(mock) for point in mock.datapoints(True): pass for point in mock.results: serialized = json.loads(to_json(point)) rt_keys = serialized["current"][""]["rt"].keys() for key in rt_keys: rt = float(key) self.assertGreaterEqual(rt, 1.0) self.assertLessEqual(rt, 2.0)
def test_speed(self): obj = self.obj mock = MockReader() mock.buffer_scale_idx = '100.0' obj.add_listener(mock) res = {} # current measurements shows ~25K samples/sec for cnt in (10, 100, 1000, 10000, 25000, 40000, 50000): for a in range(0, cnt): sample = (cnt, "", 1, r(1000), r(1000), r(1000), rc(), err(), '', 0) mock.data.append(sample) before = time.time() for point in mock.datapoints(): pass after = time.time() res[cnt] = after - before ROOT_LOGGER.info("Times: %s", res) while mock.results: point = mock.results.pop(0) overall = point[DataPoint.CURRENT][''] self.assertTrue(len(overall[KPISet.PERCENTILES]) > 0) for point in mock.datapoints(True): pass
def test_1(self): obj = self.obj mock = MockReader() mock.data.append((1, "", 1, r(), r(), r(), 200, None)) mock.data.append((2, "", 1, r(), r(), r(), 200, None)) mock.data.append((2, "", 1, r(), r(), r(), 200, None)) mock.data.append((3, "", 1, r(), r(), r(), 200, None)) mock.data.append((3, "", 1, r(), r(), r(), 200, None)) mock.data.append((4, "", 1, r(), r(), r(), 200, None)) mock.data.append((4, "", 1, r(), r(), r(), 200, None)) obj.add_listener(mock) for point in mock.datapoints(): pass mock.data.append((2, "", 1, r(), r(), r(), 200, None)) mock.data.append((2, "", 1, r(), r(), r(), 200, None)) for point in mock.datapoints(): pass for point in mock.datapoints(True): pass for point in mock.results: overall = point[DataPoint.CURRENT][''] self.assertTrue(len(overall[KPISet.PERCENTILES]) > 0)
def test_speed(self): obj = self.obj mock = MockReader() mock.buffer_scale_idx = '100.0' obj.add_listener(mock) res = {} # current measurements shows ~25K samples/sec for cnt in (10, 100, 1000, 10000, 25000, 40000, 50000): for a in range(0, cnt): sample = (cnt, "", 1, r(1000), r(1000), r(1000), rc(), err(), '', 0) mock.data.append(sample) before = time.time() for point in mock.datapoints(): pass after = time.time() res[cnt] = after - before logging.info("Times: %s", res) while mock.results: point = mock.results.pop(0) overall = point[DataPoint.CURRENT][''] self.assertTrue(len(overall[KPISet.PERCENTILES]) > 0) for point in mock.datapoints(True): pass
def test_1(self): obj = self.obj mock = MockReader() mock.buffer_scale_idx = '100.0' mock.data.append((1, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((2, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((2, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((3, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((3, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((4, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((4, "", 1, r(), r(), r(), 200, None, '', 0)) obj.add_listener(mock) for point in mock.datapoints(): self.assertNotEquals(0, point[DataPoint.CUMULATIVE][''][KPISet.CONCURRENCY]) mock.data.append((2, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((2, "", 1, r(), r(), r(), 200, None, '', 0)) for point in mock.datapoints(): pass for point in mock.datapoints(True): pass for point in mock.results: overall = point[DataPoint.CURRENT][''] self.assertTrue(len(overall[KPISet.PERCENTILES]) > 0)
def get_fail_reader_alot(offset=0): mock = MockReader() for x in range(2, 200): rnd = int(random() * x) mock.data.append((x + offset, "first", 1, r(), r(), r(), 200, (random_string(1 + rnd)), '', 0)) return mock
def get_success_reader_alot(prefix='', offset=0): mock = MockReader() for x in range(2, 200): rnd = int(random() * x) mock.data.append((x + offset, prefix + random_string(1 + rnd), 1, r(), r(), r(), 200, '', '', 0)) return mock
def test_sample_ignores(self): mock = MockReader() mock.ignored_labels = ["ignore"] mock.buffer_scale_idx = '100.0' mock.data.append((1, "ignore", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((2, "ignore1", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((2, "ignore2", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((3, "not-ignore", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((3, "not-ignore", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((4, "", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((4, "", 1, r(), r(), r(), 200, None, '', 0)) for point in mock.datapoints(True): self.assertNotIn("ignore", point[DataPoint.CUMULATIVE].keys()) self.assertNotIn("ignore1", point[DataPoint.CUMULATIVE].keys()) self.assertNotIn("ignore2", point[DataPoint.CUMULATIVE].keys())
def test_negative_response_time_scaling_crash(self): obj = ConsolidatingAggregator() obj.track_percentiles = [0.0, 50.0, 95.0, 99.0, 100.0] obj.prepare() self.sniff_log(obj.log) mock = MockReader() mock.data.append((1, "first", 1, -r(), r(), r(), 200, 'FAILx3', '', 0)) mock.data.append((2, "first", 1, -r(), r(), r(), 200, 'FAILx1', '', 0)) mock.data.append((5, "first", 1, -r(), r(), r(), 200, None, '', 0)) mock.data.append( (7, "second", 1, -r(), r(), r(), 200, 'FAILx3', '', 0)) mock.data.append((3, "first", 1, -r(), r(), r(), 200, 'FAILx3', '', 0)) mock.data.append( (6, "second", 1, -r(), r(), r(), 200, 'unique FAIL', '', 0)) obj.add_underling(mock) obj.check() for point in obj.datapoints(): obj.log.info(to_json(point)) self.assertIn("Negative response time reported", self.log_recorder.warn_buff.getvalue())
def get_success_reader_shrinking_labels(max_label_size=20, count=500): mock = MockReader() half_size = max_label_size // 2 for x in range(2, count): target_size = max_label_size - int(float(half_size) * float(x) / float(count)) label = random_url(target_size) mock.data.append((x, label, 1, r(), r(), r(), 200, '', '', 0)) return mock
def test_0buffer_scaling(self): obj = self.obj mock = MockReader() obj.add_listener(mock) # t_stamp, label, conc, r_time, con_time, latency, r_code, error, trname mock.min_buffer_len = 1 mock.buffer_len = 1 mock.buffer_multiplier = 1 mock.buffer_scale_idx = '50.0' buffer_len = mock.buffer_len for i in range(5): mock.data.append((100 + i, "", 1, 2, 2, 2, 200, None, '', 0)) points = list(mock.datapoints()) points = list(mock.datapoints()) self.assertTrue(mock.buffer_len > buffer_len) buffer_len = mock.buffer_len for i in range(10): mock.data.append((200 + i, "", 1, 3, 3, 3, 200, None, '', 0)) points = list(mock.datapoints()) points = list(mock.datapoints()) self.assertTrue(mock.buffer_len > buffer_len) buffer_len = mock.buffer_len for i in range(20): mock.data.append((300 + i, "", 1, 4, 4, 4, 200, None, '', 0)) points = list(mock.datapoints()) points = list(mock.datapoints()) self.assertTrue(mock.buffer_len > buffer_len) buffer_len = mock.buffer_len for i in range(15): mock.data.append((400 + i, "", 1, 1, 1, 1, 200, None, '', 0)) points = list(mock.datapoints()) points = list(mock.datapoints()) self.assertTrue(mock.buffer_len < buffer_len) buffer_len = mock.buffer_len for i in range(30): mock.data.append((500 + i, "", 1, 1, 1, 1, 200, None, '', 0)) points = list(mock.datapoints()) points = list(mock.datapoints()) self.assertTrue(mock.buffer_len < buffer_len)
def get_fail_reader(offset=0): mock = MockReader() mock.data.append((1 + offset, "first", 1, r(), r(), r(), 200, 'FAILx3', '', 0)) mock.data.append((2 + offset, "first", 1, r(), r(), r(), 200, 'FAILx1', '', 0)) mock.data.append((5 + offset, "first", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((7 + offset, "second", 1, r(), r(), r(), 200, 'FAILx3', '', 0)) mock.data.append((3 + offset, "first", 1, r(), r(), r(), 200, 'FAILx3', '', 0)) mock.data.append((6 + offset, "second", 1, r(), r(), r(), 200, 'unique FAIL', '', 0)) return mock
def get_success_reader_selected_labels(offset=0): mock = MockReader() labels = ['http://blazedemo.com/reserve.php', 'http://blazedemo.com/purchase.php', 'http://blazedemo.com/vacation.html', 'http://blazedemo.com/confirmation.php', 'http://blazedemo.com/another.php'] for x in range(2, 200): mock.data.append((x + offset, choice(labels), 1, r(), r(), r(), 200, '', '', 0)) return mock
def configure(self, config): self.obj.engine.config.merge(config) execution = self.obj.engine.config['execution'] if isinstance(execution, list): self.obj.execution = execution[0] else: self.obj.execution = execution self.results_listener = MockReader() self.obj.engine.aggregator = ConsolidatingAggregator() self.obj.engine.aggregator.add_listener(self.results_listener)
def get_reader(self, offset=0): mock = MockReader() mock.data.append((1 + offset, "", 1, r(), r(), r(), 200, None)) mock.data.append((2 + offset, "", 1, r(), r(), r(), 200, None)) mock.data.append((2 + offset, "", 1, r(), r(), r(), 200, None)) mock.data.append((3 + offset, "", 1, r(), r(), r(), 200, None)) mock.data.append((3 + offset, "", 1, r(), r(), r(), 200, None)) mock.data.append((4 + offset, "", 1, r(), r(), r(), 200, None)) mock.data.append((4 + offset, "", 1, r(), r(), r(), 200, None)) mock.data.append((6 + offset, "", 1, r(), r(), r(), 200, None)) mock.data.append((6 + offset, "", 1, r(), r(), r(), 200, None)) mock.data.append((6 + offset, "", 1, r(), r(), r(), 200, None)) mock.data.append((5 + offset, "", 1, r(), r(), r(), 200, None)) return mock
def get_success_reader(offset=0): mock = MockReader() mock.data.append((1 + offset, "first", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((2 + offset, "second", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((2 + offset, "first", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((3 + offset, "second", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((3 + offset, "first", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((4 + offset, "third", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((4 + offset, "first", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((6 + offset, "second", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((6 + offset, "third", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((6 + offset, "first", 1, r(), r(), r(), 200, None, '', 0)) mock.data.append((5 + offset, "first", 1, r(), r(), r(), 200, None, '', 0)) return mock
def get_success_reader(offset=0): mock = MockReader() mock.data.append((1 + offset, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((2 + offset, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((2 + offset, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((3 + offset, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((3 + offset, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((4 + offset, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((4 + offset, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((6 + offset, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((6 + offset, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((6 + offset, "", 1, r(), r(), r(), 200, None, '')) mock.data.append((5 + offset, "", 1, r(), r(), r(), 200, None, '')) return mock
def configure(self, config): super(TestExternalResultsLoader, self).configure(config) self.results_listener = MockReader() self.obj.engine.aggregator = ConsolidatingAggregator() self.obj.engine.aggregator.engine = self.obj.engine self.obj.engine.aggregator.add_listener(self.results_listener)