From 180dc8cbd64ae9ba3ebfed4436f9cd76618ee398 Mon Sep 17 00:00:00 2001 From: Tanay Soni Date: Tue, 9 Jun 2020 12:46:15 +0200 Subject: [PATCH] Start Elasticsearch with a Github Action (#142) --- .github/workflows/ci.yml | 15 +++++++++++++++ test/conftest.py | 19 ++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c8fed2987..591c32534 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,16 +13,31 @@ jobs: steps: - uses: actions/checkout@v2 + + - name: Configure sysctl limits for Elasticsearch + run: | + sudo swapoff -a + sudo sysctl -w vm.swappiness=1 + sudo sysctl -w fs.file-max=262144 + sudo sysctl -w vm.max_map_count=262144 + + - name: Run Elasticsearch + uses: elastic/elastic-github-actions/elasticsearch@25ad91e35aeee806711d335fc9dec7927ae49bc6 + with: + stack-version: 7.6.0 + - name: Set up Python 3.7 uses: actions/setup-python@v2 with: python-version: 3.7 + - name: Install dependencies run: | python -m pip install --upgrade pip pip install pytest pip install -r requirements.txt pip install -e . + - name: Test with pytest run: | cd test && pytest diff --git a/test/conftest.py b/test/conftest.py index 48536c859..0702973c4 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,10 +1,10 @@ import tarfile import time import urllib.request - from subprocess import Popen, PIPE, STDOUT, run import pytest +from elasticsearch import Elasticsearch @pytest.fixture(scope='session') @@ -14,12 +14,17 @@ def elasticsearch_dir(tmpdir_factory): @pytest.fixture(scope="session") def elasticsearch_fixture(elasticsearch_dir): - thetarfile = "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.1-linux-x86_64.tar.gz" - ftpstream = urllib.request.urlopen(thetarfile) - thetarfile = tarfile.open(fileobj=ftpstream, mode="r|gz") - thetarfile.extractall(path=elasticsearch_dir) - es_server = Popen([elasticsearch_dir / "elasticsearch-7.6.1/bin/elasticsearch"], stdout=PIPE, stderr=STDOUT) - time.sleep(40) + # test if a ES cluster is already running. If not, download and start an ES instance locally. + try: + client = Elasticsearch(hosts=[{"host": "localhost"}]) + client.info() + except: + thetarfile = "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.1-linux-x86_64.tar.gz" + ftpstream = urllib.request.urlopen(thetarfile) + thetarfile = tarfile.open(fileobj=ftpstream, mode="r|gz") + thetarfile.extractall(path=elasticsearch_dir) + es_server = Popen([elasticsearch_dir / "elasticsearch-7.6.1/bin/elasticsearch"], stdout=PIPE, stderr=STDOUT) + time.sleep(40) @pytest.fixture(scope="session")