Closed sneridagh closed 2 years ago
I recall my final guess was that, because WSGI server layer does not stop listening to HTTP port between tests, it will keep handling requests between tests, independently rom the other layers, leading to unexpected DB state. And, if so, the fix would be to customize WSGI server layer to only start the server on testSetup, and also stop in on testTeardown.
The notes I passed to Victor:
WSGI server layer would be called on testTearDown before Plone sandbox layer, because is the last one alphabetically https://github.com/zopefoundation/zope.testrunner/blob/9ee7fdf1cb56003571ad24ebc33b66ebb25ec299/src/zope/testrunner/runner.py#L1107
But it implements no testTearDown or testSetup. So WSGI server is only setup and teardown once, and therefore it is definitely listening for cyprus between tests and passing calls to Plone WSGI app.
Quick idea: Inherit a custom WSGI server layer from https://github.com/plone/plone.testing/blob/1756b024612763b8c84115ecaf4de9d0c48c8f59/src/plone/testing/zope.py#L883 and change the implementation there to only start the server in testSetup and stop it in testTearDown. Then ensure with robot server verbose logging that on testTearDown WSGI goes down before database teardown.
But even if you had your own WSGI layer, which would call shutdown on the testTearDown, it would be small possibility for similar race conditions, because the server is running in a thread and it probably could not stop currently handled request. But it should be single threaded and stop the queued request. And probably fix the issue. If not, one could probably sleep & wait for the server thread to stop, but that could be another bag of worms.
https://github.com/plone/volto/runs/6253883271?check_suite_focus=true
I already talked about this with @datakurre . I think that the teardown happens in the middle of the server doing something (like creating images scales, or other unfinished task), then you tear it down (via the xmlrpc call) then it complains hard.
With @datakurre we saw that maybe the Layers in the RobotFramework fixture should be reordered so they are tore down correctly... but this scapes to my knowledge of this matter.
/cc @ericof @davisagli @tisto
I can see a lot of these: