This PR also removes deprecated tests, adds checks to avoid races reproduced on CI/CD.
Continuation of the changes done in PR #8351 to refactor, add tests and move global handling into a more idiomatic style for Go as packages.