Fix tests on targets that don't support thread_local

This also reverts r187197.