Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to increase timeout and to specify wait strategy #10

Merged
merged 10 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
CI_JOB_ID: ${{ github.job }}-${{ matrix.python-version }}
CI_JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
CI_JOB_NAME: ${{ github.job }}-${{ matrix.python-version }}
TINYBIRD_TIMEOUT: 10
TINYBIRD_WAIT: false
run: |
tox -e py -- --report-to-tinybird
lint:
Expand Down
10 changes: 7 additions & 3 deletions pytest_tinybird/tinybird.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class TinybirdReport:
def __init__(self, config: Config):
self.config = config
self.base_url = os.environ.get("TINYBIRD_URL")
self.timeout = int(os.environ.get("TINYBIRD_TIMEOUT", REQUEST_TIMEOUT))
self.wait = os.environ.get("TINYBIRD_WAIT", "false")
self.datasource_name = os.environ.get("TINYBIRD_DATASOURCE")
self.token = os.environ.get("TINYBIRD_TOKEN")
self.url = f"{self.base_url}/v0/events?name={self.datasource_name}&token={self.token}"
self.commit = os.environ.get('CI_COMMIT_SHA', 'ci_commit_sha_unknown')
self.job_id = os.environ.get('CI_JOB_ID', 'ci_job_id_unknown')
self.job_url = os.environ.get('CI_JOB_URL', 'job_url_unknown')
Expand All @@ -30,6 +31,9 @@ def __init__(self, config: Config):
'CI_MERGE_REQUEST_SOURCE_BRANCH_NAME',
os.environ.get('CI_COMMIT_BRANCH', 'ci_commit_branch_unknown')
)
self.url = f"{self.base_url}/v0/events?name={self.datasource_name}" \
f"&token={self.token}" \
f"&wait={self.wait}"

def report(self, session: Session):
if None in [self.base_url, self.datasource_name, self.token]:
Expand Down Expand Up @@ -66,8 +70,8 @@ def report(self, session: Session):
response = requests.post(
self.url,
data=data,
timeout=REQUEST_TIMEOUT)
if response.status_code != 202:
timeout=self.timeout)
if response.status_code not in [200, 202]:
log.error("Error while uploading to tinybird %s", response.status_code)

@pytest.hookimpl(trylast=True)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
packages=['pytest_tinybird'],
author='jlmadurga',
author_email='jlmadurga@gmail.com',
version='0.2.0',
version='0.3.0',
url='https://github.com/jlmadurga/pytest-tinybird',
license='MIT',
install_requires=[
Expand Down
10 changes: 7 additions & 3 deletions tests/test_tinybird.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
from unittest import mock
import os

Expand All @@ -17,15 +18,18 @@ def test_flaky():
tinybird_url = os.environ["TINYBIRD_URL"] = 'https://fake-api.tinybird.co'
datasource_name = os.environ["TINYBIRD_DATASOURCE"] = "test_datasource"
tinybird_token = os.environ["TINYBIRD_TOKEN"] = 'test_token'
timeout = os.environ["TINYBIRD_TIMEOUT"] = "10"
wait = os.environ["TINYBIRD_WAIT"] = random.choice(['true', 'false'])

with mock.patch('requests.post') as mock_post:
mock_post.return_value.status_code = 202
mock_post.return_value.status_code = 200 if wait == 'true' else 200
alexon1234 marked this conversation as resolved.
Show resolved Hide resolved
testdir.runpytest(
"-n 2",
'--report-to-tinybird',
'-vvv'
)
mock_post.assert_called_once_with(f"{tinybird_url}/v0/events?name={datasource_name}"
f"&token={tinybird_token}",
f"&token={tinybird_token}"
f"&wait={wait}",
data=mock.ANY,
timeout=2)
timeout=int(timeout))
Loading