From 03e5852acf406488da0b34e9de4fe79d0c8dd9ae Mon Sep 17 00:00:00 2001 From: Guillermo Rodriguez Date: Wed, 2 Sep 2020 11:56:39 -0300 Subject: [PATCH] Added some missing CI integration pieces --- .github/workflows/ci.yml | 2 +- tests/conftest.py | 19 ++++++++++++++++--- tests/test_streaming.py | 21 +++++++++++++-------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index afae0a5..cd06b9f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: - name: Setup python uses: actions/setup-python@v2 with: - python: '3.8' + python-version: '3.8' - name: Install dependencies run: pip install -U . --upgrade-strategy eager - name: Run MyPy check diff --git a/tests/conftest.py b/tests/conftest.py index 24b0f92..a95165e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,6 +8,9 @@ import random import signal import platform import time +import enum + +from typing import Optional import pytest import tractor @@ -74,11 +77,21 @@ def spawn_backend(request): return request.config.option.spawn_backend +class CIEnvoirment(enum.Enum): + Travis = 'TRAVIS' + Github = 'GITHUB' + + @pytest.fixture(scope='session') -def travis(): - """Bool determining whether running inside TravisCI. +def ci_env() -> Optional[CIEnvoirment]: + """Detect CI envoirment. """ - return os.environ.get('TRAVIS', False) + if os.environ.get('TRAVIS'): + return CIEnvoirment.Travis + elif os.environ.get('CI'): + return CIEnvoirment.Github + else: + return None @pytest.fixture(scope='session') diff --git a/tests/test_streaming.py b/tests/test_streaming.py index 00b07cb..243ac30 100644 --- a/tests/test_streaming.py +++ b/tests/test_streaming.py @@ -9,6 +9,8 @@ import trio import tractor import pytest +from conftest import CIEnvoirment + def test_must_define_ctx(): @@ -202,12 +204,15 @@ async def cancel_after(wait): @pytest.fixture(scope='module') -def time_quad_ex(arb_addr, travis, spawn_backend): - if travis and spawn_backend == 'mp' and (platform.system() != 'Windows'): - # no idea, but the travis, mp, linux runs are flaking out here often - pytest.skip("Test is too flaky on mp in CI") +def time_quad_ex(arb_addr, ci_env, spawn_backend): + if ci_env in (CIEnvoirment.Github, CIEnvoirment.Travis): + if spawn_backend == 'mp' and (platform.system() != 'Windows'): + """no idea, but the travis and github actions, mp *nix runs are + flaking out here often + """ + pytest.skip("Test is too flaky on mp in CI") - timeout = 7 if platform.system() == 'Windows' else 4 + timeout = 7 if platform.system() in ('Windows', 'Darwin') else 4 start = time.time() results = tractor.run(cancel_after, timeout, arbiter_addr=arb_addr) diff = time.time() - start @@ -215,12 +220,12 @@ def time_quad_ex(arb_addr, travis, spawn_backend): return results, diff -def test_a_quadruple_example(time_quad_ex, travis, spawn_backend): +def test_a_quadruple_example(time_quad_ex, ci_env, spawn_backend): """This also serves as a kind of "we'd like to be this fast test".""" results, diff = time_quad_ex assert results - this_fast = 6 if platform.system() == 'Windows' else 2.5 + this_fast = 6 if platform.system() in ('Windows', 'Darwin') else 2.5 assert diff < this_fast @@ -229,7 +234,7 @@ def test_a_quadruple_example(time_quad_ex, travis, spawn_backend): list(map(lambda i: i/10, range(3, 9))) ) def test_not_fast_enough_quad( - arb_addr, time_quad_ex, cancel_delay, travis, spawn_backend + arb_addr, time_quad_ex, cancel_delay, ci_env, spawn_backend ): """Verify we can cancel midway through the quad example and all actors cancel gracefully.