Cap afn:wait() function wait

The afn:wait() function is intended only for testing but can be used to
request excessive waits that block query processing threads
indefinitely.  This commit improves the implementation as follows:

- Refuses to wait longer than the query timeouts (if any)
- Refuses to wait if elapsed time plus wait time would exceed overall
  query timeout
- Refuses to wait longer than a static controlled maximum
- Refuses to wait if query excecution has been cancelled
4 files changed