We were running into data race issues where the `fn.is_file()`
check would occur twice before writing the file in the `else`
clause. For this reason, a new aurweb.lock.Lock class has been
added which doubles as a thread and process lock. We can use
this elsewhere in the future, but we are also able to use it
to solve this kind of data race issue.
That being said, we still need the lock file state to tell us
when the first caller acquired the lock.
Signed-off-by: Kevin Morris <kevr@0cost.org>
Changes:
- util/sendmail now populates email files in the 'test-emails' directory.
- util/sendmail does this in a serialized fashion based off of
the test suite and name retrieved from PYTEST_CURRENT_TEST
in the format: `<test_suite>_<test_function>.n.txt` where n
is increased by one every time sendmail is run.
- pytest conftest fixtures have been added for test email setup;
it wipes out old emails for the particular test function being run.
- New aurweb.testing.email.Email class allows developers to test
against emails stored by util/sendmail. Simple pass the serial
you want to test against, starting at serial = 1; e.g. Email(serial).
Signed-off-by: Kevin Morris <kevr@0cost.org>
This change utilizes pytest-xdist to perform a multiproc test
run and reworks aurweb.db's code. We no longer use a global
engine, session or Session, but we now use a memo of engines
and sessions as they are requested, based on the PYTEST_CURRENT_TEST
environment variable, which is available during testing.
Additionally, this change strips several SQLite components
out of the Python code-base.
SQLite is still compatible with PHP and sharness tests, but
not with our FastAPI implementation.
More changes:
------------
- Remove use of aurweb.db.session global in other code.
- Use new aurweb.db.name() dynamic db name function in env.py.
- Added 'addopts' to pytest.ini which utilizes multiprocessing.
- Highly recommended to leave this be or modify `-n auto` to
`-n {cpu_threads}` where cpu_threads is at least 2.
Signed-off-by: Kevin Morris <kevr@0cost.org>