tests: reduce runtime
This refactors some tests to reduce the runtime of those.
I looked at the first five tests from #20128 (closed) but the other two did not seem to be possible to improve (CPU bound + a necessary timeout of 1 second).
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines