Run tests on Travis and fix some compatibility issues

obj is a socket object if a socket was passed instead of a fd.

Tornado test suite requires that not only the fd but also the socket object is getting closed if a socket object is passed to add_handler (https://github.com/tornadoweb/tornado/blob/master/tornado/test/ioloop_test.py#L224).