Fix data races in state/apiserver tests

> I suppose the issue could have been that you were writing to bytes.Buffer in one goroutine and then reading from it in another without actually having a synchronization primative.

Yes, that's the issue. There's a "tailer" that is operating in the background, writing to the buffer while we're checking its contents.

> Would it be better to add [synchronization] rather than force it to go through a channel send so that the output.Write and the output.String occur in the same goroutine?

Using a channel like this provides a convenient way of waking up the test when the background task is done. Using a mutex doesn't give you that.