Make sure pollUntil helper does not time out immediately

Also normalises the type of the returned error, which before had
been either 'Error' or 'ScriptTimeout' depending upon which part
of the system timed out first. Now it is always 'ScriptTimeout'.

Includes some basic tests that did not exist previously due to
time constraints. Untested code is broken code.

Fixes #1.

(cherry picked from commit 6963ffa6ef5f0f85ef7401011f02764db1058d6e)