How can I build a wrapper to wait for listening on a port?

Posted by BillyBBone on Stack Overflow See other posts from Stack Overflow or by BillyBBone
Published on 2010-06-10T13:19:06Z Indexed on 2010/06/10 13:22 UTC
Read the original article Hit count: 221

Filed under:
|
|
|

Hi,

I am looking for a way of programmatically testing a script written with the asyncore Python module. My test consists of launching the script in question -- if a TCP listen socket is opened, the test passes. Otherwise, if the script dies before getting to that point, the test fails.

The purpose of this is knowing if a nightly build works (at least up to a point) or not.

I was thinking the best way to test would be to launch the script in some kind of sandbox wrapper which waits for a socket request. I don't care about actually listening for anything on that port, just intercepting the request and using that as an indication that my test passed.

I think it would be preferable to intercept the open socket request, rather than polling at set intervals (I hate polling!). But I'm a bit out of my depths as far as how exactly to do this.

Can I do this with a shell script? Or perhaps I need to override the asyncore module at the Python level?

Thanks in advance,
- B

© Stack Overflow or respective owner

Related posts about python

Related posts about testing