Start measuring the number of queries on critical API calls
This commit is contained in:
parent
3627de103c
commit
469f25b64c
2 changed files with 38 additions and 15 deletions
|
@ -58,6 +58,16 @@ except ValueError:
|
|||
|
||||
app.register_blueprint(webhooks, url_prefix='/webhooks')
|
||||
|
||||
# The number of queries we run for guests on API calls.
|
||||
BASE_QUERY_COUNT = 0
|
||||
|
||||
# The number of queries we run for logged in users on API calls.
|
||||
BASE_LOGGEDIN_QUERY_COUNT = BASE_QUERY_COUNT + 2
|
||||
|
||||
# The number of queries we run for logged in users on API calls that check
|
||||
# access permissions.
|
||||
BASE_ACCESS_QUERY_COUNT = BASE_LOGGEDIN_QUERY_COUNT + 1
|
||||
|
||||
NO_ACCESS_USER = 'freshuser'
|
||||
READ_ACCESS_USER = 'reader'
|
||||
ADMIN_ACCESS_USER = 'devtable'
|
||||
|
@ -234,7 +244,10 @@ class TestUserStarredRepositoryList(ApiTestCase):
|
|||
|
||||
def test_get_stars_user(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
self.getJsonResponse(StarredRepositoryList, expected_code=200)
|
||||
|
||||
# Queries: Base + the list query
|
||||
with assert_query_count(BASE_ACCESS_QUERY_COUNT + 1):
|
||||
self.getJsonResponse(StarredRepositoryList, expected_code=200)
|
||||
|
||||
def test_star_repo_guest(self):
|
||||
self.postJsonResponse(StarredRepositoryList,
|
||||
|
@ -246,8 +259,11 @@ class TestUserStarredRepositoryList(ApiTestCase):
|
|||
|
||||
def test_star_and_unstar_repo_user(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
json = self.getJsonResponse(StarredRepositoryList)
|
||||
assert json['repositories'] == []
|
||||
|
||||
# Queries: Base + the list query
|
||||
with assert_query_count(BASE_ACCESS_QUERY_COUNT + 1):
|
||||
json = self.getJsonResponse(StarredRepositoryList)
|
||||
assert json['repositories'] == []
|
||||
|
||||
json = self.postJsonResponse(StarredRepositoryList,
|
||||
data={
|
||||
|
@ -1199,12 +1215,19 @@ class TestFindRepos(ApiTestCase):
|
|||
|
||||
class TestListRepos(ApiTestCase):
|
||||
def test_listrepos_asguest(self):
|
||||
json = self.getJsonResponse(RepositoryList, params=dict(public=True))
|
||||
# Queries: Base + the list query
|
||||
with assert_query_count(BASE_QUERY_COUNT + 1):
|
||||
json = self.getJsonResponse(RepositoryList, params=dict(public=True))
|
||||
|
||||
self.assertEquals(len(json['repositories']), 1)
|
||||
|
||||
def test_listrepos_orgmember(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
json = self.getJsonResponse(RepositoryList, params=dict(public=True))
|
||||
|
||||
# Queries: Base + the list query
|
||||
with assert_query_count(BASE_LOGGEDIN_QUERY_COUNT + 1):
|
||||
json = self.getJsonResponse(RepositoryList, params=dict(public=True))
|
||||
|
||||
self.assertGreater(len(json['repositories']), 1)
|
||||
|
||||
def test_listrepos_filter(self):
|
||||
|
@ -1373,7 +1396,6 @@ class TestGetRepository(ApiTestCase):
|
|||
|
||||
self.assertEquals(True, json['is_public'])
|
||||
self.assertEquals(False, json['is_organization'])
|
||||
self.assertEquals(False, json['is_building'])
|
||||
|
||||
self.assertEquals(False, json['can_write'])
|
||||
self.assertEquals(False, json['can_admin'])
|
||||
|
@ -1398,7 +1420,6 @@ class TestGetRepository(ApiTestCase):
|
|||
|
||||
self.assertEquals(True, json['can_write'])
|
||||
self.assertEquals(True, json['can_admin'])
|
||||
self.assertEquals(True, json['is_building'])
|
||||
self.assertEquals(False, json['is_organization'])
|
||||
|
||||
def test_getrepo_org_asnonmember(self):
|
||||
|
@ -1546,7 +1567,8 @@ class TestRepoBuilds(ApiTestCase):
|
|||
def test_getrepo_nobuilds(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
with assert_query_count(4):
|
||||
# Queries: Base + the list query
|
||||
with assert_query_count(BASE_ACCESS_QUERY_COUNT + 1):
|
||||
json = self.getJsonResponse(RepositoryBuildList,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
||||
|
||||
|
@ -1555,7 +1577,8 @@ class TestRepoBuilds(ApiTestCase):
|
|||
def test_getrepobuilds(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
with assert_query_count(4):
|
||||
# Queries: Base + the list query
|
||||
with assert_query_count(BASE_ACCESS_QUERY_COUNT + 1):
|
||||
json = self.getJsonResponse(RepositoryBuildList,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/building'))
|
||||
|
||||
|
|
|
@ -67,13 +67,13 @@ class TestBuildLogs(RedisBuildLogs):
|
|||
if status_wrapper is not None:
|
||||
(phase, status) = status_wrapper
|
||||
|
||||
from data import model
|
||||
build_obj = model.get_repository_build(self.test_build_id)
|
||||
build_obj.phase = phase
|
||||
build_obj.save()
|
||||
|
||||
self._status = status
|
||||
if not is_get_status:
|
||||
from data import model
|
||||
build_obj = model.get_repository_build(self.test_build_id)
|
||||
build_obj.phase = phase
|
||||
build_obj.save()
|
||||
|
||||
self._status = status
|
||||
self._last_status = status
|
||||
|
||||
def _generate_script(self):
|
||||
|
|
Reference in a new issue