'A timeout handler that verifies that the given parameter matches
what is expected.'

def on_timer(self, val):

    self.assertEqual(val, self.timer_stack.pop())
    if (not self.timer_stack):
        self.ioloop.stop()
