示例#1
0
    def test_query_num_queries_is_independent_of_num_nodes_and_events(self):
        # 1 query for all the select_related's.
        expected_queries = 1
        events_per_node = 5
        num_nodes_per_group = 5
        events_per_group = num_nodes_per_group * events_per_node

        self.make_nodes_in_group_with_events(
            num_nodes_per_group, events_per_node)

        handler = events_module.EventsHandler()

        query_1_count, query_1_result = (
            count_queries(handler.query, RequestFixture(
                {'op': 'query', 'level': 'DEBUG'}, ['op', 'level'])))

        self.make_nodes_in_group_with_events(
            num_nodes_per_group, events_per_node)

        query_2_count, query_2_result = (
            count_queries(handler.query, RequestFixture(
                {'op': 'query', 'level': 'DEBUG'}, ['op', 'level'])))

        # This check is to notify the developer that a change was made that
        # affects the number of queries performed when doing an event listing.
        # If this happens, consider your prefetching and adjust accordingly.
        self.assertEqual(events_per_group, int(query_1_result['count']))
        self.assertEqual(
            expected_queries, query_1_count,
            "Number of queries has changed; make sure this is expected.")

        self.assertEqual(events_per_group * 2, int(query_2_result['count']))
        self.assertEqual(
            expected_queries, query_2_count,
            "Number of queries is not independent of the number of nodes.")
示例#2
0
    def test_query_num_queries_is_independent_of_num_nodes_and_events(self):
        # Prevent RBAC from making a query.
        self.useFixture(RBACForceOffFixture())

        expected_queries = 1
        events_per_node = 5
        num_nodes_per_group = 5
        events_per_group = num_nodes_per_group * events_per_node

        self.make_nodes_in_group_with_events(num_nodes_per_group,
                                             events_per_node)

        handler = events_module.EventsHandler()

        query_1_count, query_1_result = count_queries(
            handler.query,
            RequestFixture({
                "op": "query",
                "level": "DEBUG"
            }, ["op", "level"]),
        )

        self.make_nodes_in_group_with_events(num_nodes_per_group,
                                             events_per_node)

        query_2_count, query_2_result = count_queries(
            handler.query,
            RequestFixture({
                "op": "query",
                "level": "DEBUG"
            }, ["op", "level"]),
        )

        # This check is to notify the developer that a change was made that
        # affects the number of queries performed when doing an event listing.
        # If this happens, consider your prefetching and adjust accordingly.
        self.assertEqual(events_per_group, int(query_1_result["count"]))
        self.assertEqual(
            expected_queries,
            query_1_count,
            "Number of queries has changed; make sure this is expected.",
        )

        self.assertEqual(events_per_group * 2, int(query_2_result["count"]))
        self.assertEqual(
            query_1_count,
            query_2_count,
            "Number of queries is not independent of the number of nodes.",
        )