From 358c4dfbc2e4845b08a7ac75dcf43bbd8d4e8a05 Mon Sep 17 00:00:00 2001
From: varac <varacanero@zeromail.org>
Date: Wed, 22 Mar 2017 11:24:42 +0100
Subject: [PATCH] Post benchmark results to elastticsearch

In order to do this from CI, please create a secret variable
(at i.e. https://0xacab.org/varac/soledad/settings/ci_cd)
called PYTEST_OPTS and use this example:

    --benchmark-autosave --benchmark-storage="elasticsearch+https://USER:PASSWORD@moose.leap.se:9200"
---
 .gitignore      |  3 ++-
 .gitlab-ci.yml  | 23 +++++++++++++++++++++++
 testing/tox.ini |  5 ++++-
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index a8df15eb..1cad979a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@ MANIFEST
 *.swp
 *.swo
 *.pyc
+*.pyo
 *.log
 *.*~
 *.csv
@@ -21,4 +22,4 @@ scripts/profiling/sync/profiles
 
 testing/htmlcov
 testing/.coverage
-testing/test-env
\ No newline at end of file
+testing/test-env
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ee57c51c..da908634 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,6 +1,7 @@
 stages:
   - code-check
   - tests
+  - benchmark
 
 # Cache tox envs between builds
 cache:
@@ -22,3 +23,25 @@ tests:
   script:
     - cd testing
     - tox -- --couch-url http://couchdb:5984
+
+benchmark:
+  stage: benchmark
+  image: leapcode/soledad:latest
+  tags:
+    - benchmark
+  services:
+    - couchdb
+  allow_failure: true
+  script:
+    - cd testing
+    - curl -s couchdb:5984
+    # You can provide a $NETRC variable containing the creds for your
+    # elasticsearch instance so it's protected from being leaked in the
+    # CI console
+    # We can't get it working inside docker for unknown reasons.
+    #- echo "$NETRC" > /root/.netrc && chmod 600 /root/.netrc
+    #
+    # Add $PYTEST_OPTS to pytest.ini to allow posting benchmark tests
+    # to an elasticsearch instance
+    - echo "addopts=$PYTEST_OPTS" >> pytest.ini && chmod 600 pytest.ini
+    - tox --recreate -e benchmark -- --couch-url http://couchdb:5984
diff --git a/testing/tox.ini b/testing/tox.ini
index d959db0a..d800d988 100644
--- a/testing/tox.ini
+++ b/testing/tox.ini
@@ -62,7 +62,10 @@ install_command = pip3 install {opts} {packages}
 [testenv:benchmark]
 deps =
     {[testenv]deps}
-    pytest-benchmark
+    #pytest-benchmark>=3.1.0a2
+    git+https://github.com/drebs/pytest-benchmark.git@use-netrc-file
+    elasticsearch
+    certifi
 commands = py.test --benchmark-only {posargs}
 
 [testenv:code-check]
-- 
GitLab