'Test to validate that requests listeners.
This test creates a simple metrics based request listener to track request size, it then
check to ensure that on_success and on_error methods are invoked appropriately.
@since 3.7.0
@jira_ticket PYTHON-284
@expected_result in_error, and on_success should be invoked apropriately
@test_category metrics'

def test_metrics_per_cluster(self):

    ra = RequestAnalyzer(self.session)
    for _ in range(10):
        self.session.execute('SELECT    release_version    FROM    system.local')
    for _ in range(3):
        try:
            self.session.execute('nonesense')
        except SyntaxException:
            continue
    self.assertTrue(self.wait_for_count(ra, 10))
    self.assertTrue(self.wait_for_count(ra, 3, error=True))
    ra.remove_ra(self.session)
    ra = RequestAnalyzer(self.session, throw_on_success=False, throw_on_fail=True)
    self.session.execute('SELECT    release_version    FROM    system.local')
    ra.remove_ra(self.session)
    RequestAnalyzer(self.session, throw_on_success=True)
    try:
        self.session.execute('nonesense')
    except SyntaxException:
        pass
