Hello Milimetric,

I'd like you to do a code review.  Please visit

    https://gerrit.wikimedia.org/r/149302

to review the following change.

Change subject: Bring connection pool tests into main test suite
......................................................................

Bring connection pool tests into main test suite

The datadase connection pool tests do not require manual setup, they
can run on a plain setup, so bring them from the manual into the main
test suite.

Since one of the two tests is slow, we add a slow group and exclude it
by default. That way, it does not get in the way when developing, but
we can check it automatically before deployment.

Change-Id: Ibbbec4e432a5dba65b2a85cc0a3aa4a622a56d1e
---
M scripts/test
A tests/test_database/__init__.py
R tests/test_database/test_connection_pool_configuration.py
3 files changed, 72 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics 
refs/changes/02/149302/1

diff --git a/scripts/test b/scripts/test
index 6eef5a0..11ded25 100755
--- a/scripts/test
+++ b/scripts/test
@@ -7,4 +7,4 @@
 find . -name *.pyc | xargs --no-run-if-empty rm
 # NOTE: this script excludes certain tagged tests.  To run excluded tests, you 
can do:
 #   nosetests tests/path/to/test
-nosetests --cover-erase -a "!nonDeterministic,!manual" ./$TO_TEST
+nosetests --cover-erase -a "!nonDeterministic,!manual,!slow" ./$TO_TEST
diff --git a/tests/test_database/__init__.py b/tests/test_database/__init__.py
new file mode 100644
index 0000000..18fe30d
--- /dev/null
+++ b/tests/test_database/__init__.py
@@ -0,0 +1,69 @@
+from subprocess import Popen
+from os import devnull
+from signal import SIGINT
+from time import sleep
+from wikimetrics.configurables import queue
+
+celery_proc = None
+celery_sched_proc = None
+
+
+def celery_is_alive():
+    try:
+        from celery.task.control import inspect
+        insp = inspect()
+        d = insp.stats()
+        if d:
+            return True
+    except IOError:
+        return False
+    
+    return False
+
+
+def setUp():
+    """
+    Set global testing variables and override database names
+    so they have "_testing" as a suffix
+    """
+    setUpTestingDB()
+    
+    celery_out = open(devnull, "w")
+    # TODO have a more solid setup of celery for development
+    #celery_out = open("/tmp/logCelery.txt", "w")
+    celery_cmd = ['wikimetrics', '--mode', 'queue',
+                  '--override-config', 'wikimetrics/config/test_config.yaml']
+    global celery_proc
+    celery_proc = Popen(celery_cmd, stdout=celery_out, stderr=celery_out)
+    
+    # TODO remove from here when
+    # this bug is fixed: https://bugzilla.wikimedia.org/show_bug.cgi?id=66770
+    queue.conf['CELERY_ALWAYS_EAGER'] = True
+    
+    # wait until celery broker / worker is up
+    tries = 0
+    while(not celery_is_alive() and tries < 20):
+        tries += 1
+        sleep(0.5)
+
+
+def tearDown():
+    global celery_proc
+    if celery_proc is not None:
+        celery_proc.send_signal(SIGINT)
+
+
+def setUpTestingDB():
+    """
+        Set global testing variables.
+        By convention testing dbs are development dbs with sufix "_testing"
+        we change url connection strings so tests run on testing databases
+        Note that wikimetrics user already exists, puppet has created it.
+    """
+    # NOTE: need to import these inline, otherwise they might match the
+    # nosetests regular expression and run as tests
+    from wikimetrics.configurables import app, db, setup_testing_config
+    # Set TESTING to true so we can know to not check CSRF
+    # TODO we need a global config object
+    app.config['TESTING'] = True
+    db.config = setup_testing_config(db.config)
diff --git a/tests/manual/connection_pool_configuration.py 
b/tests/test_database/test_connection_pool_configuration.py
similarity index 95%
rename from tests/manual/connection_pool_configuration.py
rename to tests/test_database/test_connection_pool_configuration.py
index 8801684..26dcc73 100644
--- a/tests/manual/connection_pool_configuration.py
+++ b/tests/test_database/test_connection_pool_configuration.py
@@ -1,5 +1,6 @@
 from unittest import TestCase
 from sqlalchemy.exc import TimeoutError
+from nose.plugins.attrib import attr
 from nose.tools import raises
 
 from tests.fixtures import mediawiki_project
@@ -10,6 +11,7 @@
 
 class DatabaseSetupTest(TestCase):
 
+    @attr('slow')
     @raises(TimeoutError)
     def test_pool_size_can_be_exceeded(self):
         # The 11 in the following statement is 10 (default for

-- 
To view, visit https://gerrit.wikimedia.org/r/149302
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibbbec4e432a5dba65b2a85cc0a3aa4a622a56d1e
Gerrit-PatchSet: 1
Gerrit-Project: analytics/wikimetrics
Gerrit-Branch: master
Gerrit-Owner: QChris <[email protected]>
Gerrit-Reviewer: Milimetric <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to