'This method patches ``self.app`` so that after any endpoint is
rendered, the reactor used by the volume plugin is advanced repeatedly
until there are no more ``delayedCalls`` pending on the reactor.'

def _flush_volume_plugin_reactor_on_endpoint_render(self):

    real_execute_endpoint = self.app.execute_endpoint
    def patched_execute_endpoint(*args, **kwargs):
        val = real_execute_endpoint(*args, **kwargs)
        while self.volume_plugin_reactor.getDelayedCalls():
            pending_calls = self.volume_plugin_reactor.getDelayedCalls()
            next_expiration = min((t.getTime() for t in pending_calls))
            now = self.volume_plugin_reactor.seconds()
            self.volume_plugin_reactor.advance(max(0.0, (next_expiration - now)))
        return val
    self.patch(self.app, 'execute_endpoint', patched_execute_endpoint)
