python-tuf/tests/repository_data
Martin Vrachev 5d9a6f6598 Tests: Queue replace tmp files, OS port creation
These changes can be summarized with the following bullets:
- Delegate generation of ports used for the tests to the OS
- Use thread-safe Queue for processes communication
instead of temporary files
- Remove all instances of port generation or hardcoded ports
- Make test_slow_retrieval.py fully conform with TestServerProcess

Delegate generation of ports used for the tests to the OS is much
better than if we manually generate them, because there is always
a chance that the port we have randomly pick turns out to be taken.
By giving 0 to the port argument we ask the OS to give us
an arbitrary unused port.

Use thread-safe Queue for processes communication instead of temporary
files became a necessity because of findings made by Jussi Kukkonen.
With the latest changes made in pr 1192 we were rapidly reading
from the temporary files and Jussi found that it happened rarely
the successful message "bind succeded..." to be corrupted.
It seems, this is a thread issue related to the thread redirecting
the subprocess stdout to the temp file and our thread rapidly
reading from the file.
By using a thread-safe Queue we eliminate this possibility.
For reference read:
https://github.com/theupdateframework/tuf/issues/1196

Lastly, test_slow_retrieval.py and slow_retrieval.py were refactored.
Until now, slow_retrieval.py couldn't use the TestServerProcess class
from utils.py for a port generation because of a bug related to
httpd.handle_request().
Now, when we use httpd.serve_forever() we can refactor both of those
files and fully conform with TestServerProcess.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-13 14:01:57 +02:00
..
client Re-generate repository and client test metadata 2020-03-11 11:35:37 +00:00
keystore Add two ed25519 key pairs for updater tests 2019-10-07 11:59:40 +02:00
project Re-generate projects test metadata 2019-09-16 15:43:39 +02:00
repository Re-generate repository and client test metadata 2020-03-11 11:35:37 +00:00
generate.py Adopt sslib keygen interface encryption changes 2020-11-11 10:27:56 +01:00
generate_project_data.py Remove redundant test logic 2020-05-12 22:16:38 +01:00
map.json Tests: Queue replace tmp files, OS port creation 2020-11-13 14:01:57 +02:00
README.md fix-up the the -> the 2019-09-01 22:53:02 +08:00

Unit and integration testing

Running the tests

The unit and integration tests can be executed by invoking tox from any path under the project directory.

$ tox

Or by invoking aggregate_tests.py from the tests directory.

$ python aggregate_tests.py

Note: integration tests end in _integration.py.

If you wish to run a particular unit test, navigate to the tests directory and run that specific unit test. For example:

$ python test_updater.py

It it also possible to run the test cases of a unit test. For instance:

$ python -m unittest test_updater.TestMultiRepoUpdater.test_get_one_valid_targetinfo

Setup

The unit and integration tests operate on static metadata available in the repository_data directory. Before running the tests, static metadata is first copied to temporary directories and modified, as needed, by the tests.

The test modules typically spawn HTTP(S) servers that serve metadata and target files for the unit tests. The map file specifies the location of the test repositories and other properties. For specific targets and metadata provided by the tests repositories, please inspect their respective metadata.