From 1c72cbe44eafa7f8903d110487a1390c8f659209 Mon Sep 17 00:00:00 2001 From: Morty Space Date: Sat, 14 May 2022 22:18:53 +0200 Subject: [PATCH] Added proper timeouts --- .github/workflows/test.yml | 1 + azure-pipelines.yml | 61 ----------------------------------- src/cryptocom/exchange/api.py | 4 +-- tests/test_market.py | 8 ++--- 4 files changed, 5 insertions(+), 69 deletions(-) delete mode 100644 azure-pipelines.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7a911c0..e99a168 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -75,6 +75,7 @@ jobs: - name: Test docs run: . activate.sh && cd docs && make doctest && cd .. - name: Test code + timeout-minutes: 5 run: . activate.sh && poetry run pytest -v --cov . --cov-report xml:coverage.xml - name: Send codeclimate analytics run: ./cc-test-reporter after-build -r ${{ secrets.CC_TEST_REPORTER_ID }} --exit-code $? diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 4d1e5a6..0000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,61 +0,0 @@ ---- -trigger: - - master -schedules: - - cron: 0 0 * * * - displayName: Daily test run - branches: - include: - - master - always: true -variables: - - name: CRYPTOCOM_API_KEY - value: PCuweiWhHJC339hHdMdcVC - - name: CRYPTOCOM_API_SECRET - value: mXYtwLajZdFGU56mDo8eqL - - name: CC_TEST_REPORTER_ID - value: 16bcfb0958d99f11456f8d80aeb5800d567724471e151fe6e74a4b329b45dcb6 -pool: - vmImage: ubuntu-20.04 -strategy: - maxParallel: 1 - matrix: - Python37: - python.version: '3.7' - Python38: - python.version: '3.8' - Python39: - python.version: '3.9' - Python310: - python.version: '3.10' -steps: - - checkout: self - persistCredentials: true - clean: true - - task: UsePythonVersion@0 - inputs: - versionSpec: $(python.version) - displayName: Use Python $(python.version) - - script: | - python -m pip install --upgrade pip - pip install poetry - poetry install - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter - ./cc-test-reporter before-build - displayName: Install dependencies - - script: | - git pull origin master - poetry run python generatestructs.py - git config --global user.email "morty.space@gmail.com" - git config --global user.name "Morty Space" - git add -A . - git commit -m "[JOB] Updated API pairs and coins" - git push origin HEAD:master - displayName: Update API structs - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - # - script: | - # cd docs && make doctest && cd .. - # poetry run pytest -v --cov . --cov-report xml:coverage.xml - # ./cc-test-reporter after-build --exit-code $? - # displayName: Run tests diff --git a/src/cryptocom/exchange/api.py b/src/cryptocom/exchange/api.py index a1b538c..9ccf12c 100644 --- a/src/cryptocom/exchange/api.py +++ b/src/cryptocom/exchange/api.py @@ -269,10 +269,10 @@ class ApiProvider: async for ws in websockets.connect(url, open_timeout=self.timeout): try: dataiterator = ApiListenAsyncIterable(self, ws, channels, sign) - async with async_timeout.timeout(120) as tm: + async with async_timeout.timeout(70) as tm: async for data in dataiterator: if data: - tm.shift(120) + tm.shift(70) yield data except (websockets.ConnectionClosed, asyncio.TimeoutError): continue diff --git a/tests/test_market.py b/tests/test_market.py index 6ed0bc9..4cffb7c 100644 --- a/tests/test_market.py +++ b/tests/test_market.py @@ -78,17 +78,13 @@ async def test_listen_candles(exchange: cro.Exchange): @pytest.mark.asyncio async def test_listen_trades(exchange: cro.Exchange): trades = [] - count = 0 - pairs = [cro.pairs.CRO_USDT, cro.pairs.BTC_USDT] + pairs = [cro.pairs.BTC_USDC, cro.pairs.BTC_USDT] pairs_seen = set() async for trade in exchange.listen_trades(*pairs): trades.append(trade) pairs_seen.add(trade.pair) - if count > 100: + if len(pairs_seen) == len(pairs) and len(trades) > 30: break - count += 1 - - assert len(pairs_seen) == len(pairs) @pytest.mark.asyncio