Skip to content

Commit

Permalink
Merge run-less-tests into main
Browse files Browse the repository at this point in the history
What does this change intend to accomplish?

This limits the amount of requests sent to the Pandora api to 1/5. It also adds some delays to further reduce the request intensity.

NOTE: We may need to limit these requests further by hiding them behind a command line argument. That would be an extra step that may lead to us missing test failures. Lets try this for now and see what kind of mileage we can get out of it.

Checklist

- [x] Have you tested your changes and ensured they work?
- [x] Have you checked to ensure there aren't other open Pull Requests for the same update/change?
- [x] Does your submission pass linting & tests? You can test on localhost using ./scripts/test
  • Loading branch information
linknum23 committed May 21, 2024
2 parents 5414f38 + f78da3f commit 9f87c02
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import os
from copy import deepcopy # copy test config

# add some random delays to stream commands
from time import sleep
import random

import pytest
from fastapi.testclient import TestClient

Expand Down Expand Up @@ -151,7 +155,7 @@ def client(request):
c.original_config = deepcopy(cfg) # add the loaded config so we can remember what was loaded
return c

@pytest.fixture(params=[base_config_copy(), base_config_no_presets(), base_config_no_groups(), base_config_no_streams(), base_config_vol_db()])
@pytest.fixture(params=[base_config_copy()])
def clientnm(request):# Non-mock systems should use this client - mock_ctrl and mock_streams are False here
""" AmpliPi instance connected to a real AmpliPi controller """
cfg = request.param
Expand Down Expand Up @@ -750,6 +754,9 @@ def test_post_stream_cmd_live(clientnm, cmd):
rv = clientnm.patch('/api/sources/0', json={'input': f'stream={sid}'})
assert rv.status_code == HTTPStatus.OK
jrv = rv.json()
# delay a bit to avoid bombarding pandoras API with too many requests avoiding the rate limiter
# the random delay attempts to avoid collisions when running the tests in parallel
sleep(random.uniform(1, 5))
# the check below will fail when run in parallel with other tests, why is the configuration different than expected????
assert not jrv['info']['mock_streams']
rv = clientnm.post('/api/streams/{}/{}'.format(sid, cmd))
Expand Down

0 comments on commit 9f87c02

Please sign in to comment.