Fix broken websocket test

- extract common functionality into a mini reflection library
- made reflection code a lot more robust (though not well tested)