Commit Graph

84 Commits

Author SHA1 Message Date
Tim Abbott 8339c21637 test-backend: Fix db issues with running two copies in parallel.
Sometimes it's useful to run two copies of test-backend at the same
time.  The problem with doing so is that we need to make sure no two
threads are using the same test database ID.

Previously, this worked only if at most one of those copies was
running in the single-threaded mode, because we used a random database
ID for the single-threaded code path, but the same IDs counting from 0
for the parallel code path.

Fix this, mostly, by generating a random start for the range of IDs
used by the process, and then counting off database IDs starting from
there (both in the parallel and non-paralllel modes).

There's still a very low probability race, see the TODO.
Additionally, there appear to be some other races with running two
copies of test-backend at the same time not related to the database.

See https://github.com/zulip/zulip/issues/12426 for a follow-up issue
that's sorta created by this.
2019-05-28 16:38:45 -07:00
Anders Kaseorg 643bd18b9f lint: Fix code that evaded our lint checks for string % non-tuple.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-04-23 15:21:37 -07:00
Raymond Akornor 4dc7f5354d tests: Optimize test-backend performance.
This optimizes test-backend by skipping webhook
tests when run in default mode.

Tweaked by tabbott to extend the documentation and update the CI
commands.
2019-02-19 14:50:41 -08:00
Anders Kaseorg f0ecb93515 zerver core: Remove unused imports.
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-02-02 17:41:24 -08:00
Aditya Bansal a68376e2ba zerver/lib: Change use of typing.Text to str. 2018-05-12 15:22:39 -07:00
Patrick Grave 008e250668 mypy: Use Python 3 syntax for typing in test_runner.py 2018-01-23 08:49:42 -08:00
Umair Khan ea8f1efb63 tests: Re-raise exception if not import error. 2018-01-19 06:02:05 -05:00
Umair Khan 8f316183e0 tests: Make import error tracebacks terse.
This will also disable exception chaining; we do not need it here.
2018-01-19 06:02:05 -05:00
Umair Khan a994dba583 tests: Give more descriptive import error.
This code takes care of the environment running Python 3.4 when
test label is passed directly to the test-backend command:
./tools/test-backend test_alert_words
2018-01-18 07:13:26 -05:00
Umair Khan 0eda941822 tests: Verify imports in test modules. 2018-01-18 07:13:26 -05:00
Umair Khan 7248a3366b tests: Change print_error_message to check_import_error. 2018-01-18 07:13:26 -05:00
Umair Khan f3c86c9e58 tests: Remove old import testing code.
We will add the modified version of this code in the next commit.
2018-01-18 07:13:26 -05:00
Umair Khan c26cdee95d get_test_names: Update to accept ParallelTestSuite arg. 2018-01-18 07:13:26 -05:00
Alena Volkova aa58e1fcda tests: Make import failure error messages more consistent. 2018-01-18 07:13:26 -05:00
Alena Volkova 13b1334fe4 tests: Refactor error handling of import failures. 2018-01-18 07:13:26 -05:00
Alena Volkova 5bbc46762f tests: Improve error handling of import failures.
Fixes #6776.
2018-01-05 12:03:37 -05:00
Steve Howell f83a73c763 mypy: Use more specific type for _replacement_destroy_test_db. 2017-12-08 19:00:18 -08:00
rht 33b1a541d7 zerver/lib: Use python 3 syntax for typing.
With tweaks by tabbott to fix line spacing.
2017-11-18 16:09:04 -08:00
derAnfaenger 19bc55aa45 Fix various typos.
The typos and their corrections were found with the
aid of https://github.com/lucasdemarchi/codespell.
2017-11-09 16:26:38 +01:00
neiljp (Neil Pilgrim) 4194dcfff1 mypy: set SubSuiteList to inherit from typed List.
Modified by tabbott to add the `type: ignore`, which is basically
required by the monkey-patching we're doing here.
2017-11-07 11:39:21 -08:00
neiljp (Neil Pilgrim) 2a2870eec8 mypy: Fully specify type of Callable parameter to process_instrumented_calls. 2017-11-04 19:47:45 -07:00
neiljp (Neil Pilgrim) 5ec855967d mypy: Constrain return types to match in test_runner.py. 2017-10-31 00:03:35 -07:00
rht c4fcff7178 refactor: Replace super(.*self) with Python 3-specific super().
We change all the instances except for the `test_helpers.py`
TimeTrackingCursor monkey-patching, which actually needs to specify
the base class.
2017-10-30 14:30:25 -07:00
Tim Abbott bfa148ab39 requirements: Update mypy to latest version.
This involves fixing the mypy annotations in one file
2017-10-27 17:05:52 -07:00
Tim Abbott 073c81bbe8 slow_tests: Increase limit for TOO slow notices. 2017-10-27 15:38:17 -07:00
rht 2e12fe5e2e zerver/lib: Remove print_function. 2017-09-27 18:05:45 -07:00
Tim Abbott b8e7369dee mypy: Remove type: ignores not needed in Python 3. 2017-08-25 11:04:20 -07:00
Umair Khan 782bfd1d7c test_runner: Support only Django version >= 1.11.
In previous versions, the argument to run_subsuite is a tuple of
length 3, while in versions >= 1.11 it's a tuple of length 4.
2017-07-10 11:32:10 -07:00
Umair Khan 8660e002bb Django 1.11: Upgrade parallel test runner.
In Django 1.11, args argument of run_subsuite function is a tuple of
length 4. The new argument is the test runner class which we do not
need because we run tests using our own version of the test runner.
2017-06-13 15:04:04 -07:00
Umair Khan b09b60dfff Revert "test-backend: Enable test coverage in multi-process mode."
This reverts commit a22d6d2c2a.
2017-06-06 13:07:16 +05:00
Jason Michalski a22d6d2c2a test-backend: Enable test coverage in multi-process mode.
We enable data_suffix option when creating Coverage instances which
causes the output files to include the hostname, pid, and random id.
Before each run erase is called which clears all existing coverage data
files. And then at the end of the test run use the combine method which
merges the reports.

We collect coverage in the main process which collects data from
imports and also when running in single process mode. In the workers we
collect coverage in run_subsuite. This creates more stats files than
strictly required but I don't see a better place to save the stats when
stopping workers.

Note that this has the side effect of enabling parallel testing in
Travis CI.
2017-05-23 18:25:13 -07:00
Aditya Bansal b7c49299a6 pep8: Add compliance with rule E261 to test_runner.py. 2017-05-18 03:00:32 +05:30
Umair Khan 4971b7ff9f testing: Add errored tests to failed tests list.
Fixes: #4716.
2017-05-09 09:36:59 -07:00
Umair Khan c62150c097 testing: Bounce redis key prefix per test.
This commit adds a prefix to the redis keys; this allows us
to easily bounce the redis cache before every test.

Fixes: #1212
2017-05-05 18:24:08 +05:00
Umair Khan ce5980aa45 testing: Don't destroy template DB in parallel mode. 2017-04-26 13:59:42 +05:00
Umair Khan 86ebc2ccb1 testing: Reset INSTRUMENTED_CALLS for subsuites.
We need to reset INSTRUMENTED_CALLS variable before running every
subsuite. If we do not do this then the subsuite running on a
particular process called A will send the accumulated instrumented
calls gathered by the previous subsuites which also ran on the process A.

This also fixes the extra delay that we used to experience after the
tests had finished running. The extra delay was due to the duplicate
instrumented calls in the INSTRUMENTED_CALLS list. The size of this
list used to be ~100k for parallel model as opposed to ~1800 for serial
model.
2017-04-25 09:07:15 -07:00
Umair Khan d4ca0f1751 testing: Create one upload directory per process.
This commit creates a dedicated file upload directory for every process
when we are running tests in parallel mode. This makes sure that we do
not run into any race conditions due to multiple processes accessing
the same upload directory.
2017-04-25 09:07:15 -07:00
Umair Khan 93b4200cae testing: Move _worker_id incrementer block to the top.
Incrementing the _worker_id should be the first step for the process.
It gives better structure to the code.
2017-04-25 09:07:15 -07:00
Umair Khan ea0288c4d0 testing: Create DB only in init_worker for parallel mode.
This commit has no bearing on serial mode performance. For parallel
mode, this will reduce the overhead of one instance of DB
destruction/creation.
2017-04-18 09:10:38 -07:00
Umair Khan 740a6c8081 test_runner.py: Add a docstring to init_worker(). 2017-04-18 09:08:17 -07:00
Tim Abbott 622b7f00f7 test_runner: Fix unnecessary sleep(1) in database teardown.
Apparently, Django's _destroy_test_db has a mostly unnecessary
sleep(1) before dropping the database, which obviously wastes a bunch
of time in the single-test runtime of their database teardown logic.

We work around this by monkey-patching that function to not do the sleep.
2017-04-14 09:30:47 -07:00
Umair Khan a507a47778 testing: Use zulip_test_template for backend.
Instead of zulip_test, use zulip_test_template for backend DB. This
makes sure that the DB used by backend tests is different from the
DB, which will be zulip_test, used by Casper tests.
2017-04-14 10:23:31 +05:00
Umair Khan c9140dfa4c testing: Use a random database name when running backend tests.
This decreases risk of conflicts between running the backend and
casper test suites.

Part of #1977.
2017-04-12 13:17:40 -07:00
Umair Khan 65b96aab0c testing: Extract functions to create/destroy test databases. 2017-04-12 13:17:32 -07:00
Adarsh S d54dea819d Add option for re-running failed tests.
This adds the option '--rerun' to the `test-backend` infrastructure.
It runs the tests that failed during the last 'test-backend' run.  It
works by stailing failed test info at var/last_test_failure.json

Cleaned up by Umair Khan and Tim Abbott.
2017-04-12 11:35:31 -07:00
Umair Khan 804c62045f testing: Flush API_KEYS before every test.
This makes our test performance for each test more consistent.
2017-03-22 12:07:06 -07:00
Umair Khan a2aeddba6b testing: Add infrastructure for running backend tests in parallel.
This doesn't yet provide an option to actually run the backend tests
parallelized yet.
2017-03-21 10:59:12 -07:00
Raghav Jajodia a3a03bd6a5 mypy: Added Dict, List and Set imports.
Fixed mypy errors associated with the upgrade.
2017-03-04 14:33:44 -08:00
Umair Khan dbe609d515 testing: Copy code from unittest.TestSuite.run.
This allows us to use setUpClass.
2017-02-19 21:04:06 -08:00
Umair Khan 128beb910b testing: Use TestResult in run_test.
Internally, Django uses TestResult to gather results from testcases.
This commit upgrades the run_test function to use TestResult to compile
result.
2017-02-19 21:04:06 -08:00