More work on timeout related functionality. Some rather convoluted tests, but got there in the end.