AlexsLemonade / refinebio

Refine.bio harmonizes petabytes of publicly available biological data into ready-to-use datasets for cancer researchers and AI/ML scientists.
https://www.refine.bio/
Other
126 stars 19 forks source link

Testing API throttling is inconsistent #3259

Closed davidsmejia closed 12 months ago

davidsmejia commented 1 year ago

Context

When we test throttling API requests it doesn't actually throttle every time we run our tests.

The code in question in test_api_general.py

for i in range(15):
   response = self.client.get(reverse("survey_jobs", kwargs={"version": API_VERSION}))
self.assertEqual(response.status_code, status.HTTP_429_TOO_MANY_REQUESTS)

Problem or idea

Output from a non-throttled test failing:

System check identified no issues (0 silenced).
..........F.......................Deleting index 'experiments'
Creating index 'experiments'
Indexing 2 'Experiment' objects 
.....
======================================================================
FAIL: test_all_endpoints (tests.views.test_api_general.APITestCases)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/user/tests/views/test_api_general.py", line 352, in test_all_endpoints
    self.assertEqual(response.status_code, status.HTTP_429_TOO_MANY_REQUESTS)
AssertionError: 200 != 429

----------------------------------------------------------------------
Ran 39 tests in 8.177s

Solution or next step

We should rewrite the test so that it triggers a throttled response at the end or collect the responses and check to see if throttling occurred.