Replace unsafe test code with global_counter