Fix data races in state/apiserver tests

The goroutine may continue operating while another test updates PingPeriod. This change fixes the data race on the global.