Clean up web socket test code and fix up some close handling edge cases