a lot of tests leave detritus in $TMPDIR#499
Conversation
|
We might be able to simplify this for developers with using an attribute macro on the test functions that add invocations of the context creation and teardown and uses a std::panic::catch_unwind block to detect test failure. If you want me to expand on that, I'd be happy to |
Please do. This was discussed in chat (failure detection mechanism unspecified) and we agreed we would like that very much. |
Agreed. We discussed something similar in chat. I think that's a good idea. I'd like to not block this PR on that though as I don't know that I'll be able to get to that any time soon. (If anyone else wants to, that'd be great!) |
|
I could maybe throw it together, I could use an excuse to learn to write procedural macros |
There are two common problems:
LogContextand never invokecleanup_successful(). This leaves log files hanging around in $TMPDIR.ControlPlaneTestContextand never invoketeardown(). This also leaves log files hanging around in $TMPDIR. TheDropimpls onCockroachInstanceandClickHouseInstanceshould cause those programs to shut down and their storage directories to be cleaned up, but it's not a guarantee. If not, we might leak them, using up memory in the process.This change fixes them. I did this by looking at all the log files in $TMPDIR, which are named by what test created them, finding the test, and adding the appropriate cleanup call.
Obviously, this pattern is easy to mis-use. I'd welcome improvements here. The design goal is:
Because we want to keep these around on failure, we can't have the
Dropimpls clean up these files. We want to do that only if the test fails. The only way we know if it succeeds or fails is if the programmer tells us they succeeded by callingteardown()/cleanup_successful(). We could flip the default assumption so that you have to tell us when it failed, but that seems much harder to use and more error-prone.