-
Task
-
Resolution: Unresolved
-
Medium
-
None
-
None
SIMPLY-4081 identified the controller tests as the primary time sink when running the circulation manager's test suite. Profiling reveals that the vast majority of the time is spent in setup, creating a fresh CirculationManager object for every test.
Here's the relevant output of the Python profiler after I ran this command (see below for some setup info):
pytest tests/admin/controller/test_work_editor.py --profile
ncalls tottime percall cumtime percall filename:lineno(function) 28 0.000 0.000 70.343 2.512 28 0.000 0.000 53.309 1.904 test_work_editor.py:56(setup_method) 28 0.001 0.000 53.154 1.898 test_controller.py:97(setup_method) 28 0.001 0.000 46.450 1.659 test_controller.py:317(setup_method) 28 0.000 0.000 40.803 1.457 test_controller.py:157(setup_method) 28 0.001 0.000 40.658 1.452 test_controller.py:187(circulation_manager_setup) 28 0.000 0.000 38.043 1.359 controller.py:153(__init__) 28 0.003 0.000 38.004 1.357 controller.py:225(load_settings) 56 0.001 0.000 32.073 0.573 config.py:685(key_pair) 56 0.001 0.000 31.428 0.561 RSA.py:391(generate) 112 0.180 0.002 31.410 0.280 Primality.py:279(generate_probable_prime) 38760 0.265 0.000 27.280 0.001 Primality.py:221(test_probable_prime) 38760 0.543 0.000 22.224 0.001 Primality.py:45(miller_rabin_test) 28 0.000 0.000 21.387 0.764 authenticator.py:529(__init__) 28 0.001 0.000 21.387 0.764 authenticator.py:538(populate_authenticators) 28 0.001 0.000 21.277 0.760 authenticator.py:581(from_config) 28 0.000 0.000 17.521 0.626 authenticator.py:631(__init__) 28 0.000 0.000 17.521 0.626 authenticator.py:1084(key_pair)
One way or another, we should not be creating a brand new CirculationManager object for every controller test.
The simplest way to do this is to make the CirculationManager a class-level or module-level fixture. I'd try this first and see how many problems it turns up – tests that modify the CirculationManager configuration on the assumption that no one else will need.
We can fix these tests either by having them change the CirculationManager configuration back to the way it was, or by giving them their own CirculationManager objects instead of having them use the same one everyone else uses.
While investigating this I discovered there's some code in ControllerTest.setup_method() which seems designed to try to make sure the CirculationManager setup code is only called once, but it's not doing that. It should probably be removed now that we use pytest and have a proper fixture system.