'Check that a buffered read, when it gets interrupted (either
returning a partial result or EINTR), properly invokes the signal
handler and retries if the latter returned successfully.'

def check_interrupted_read_retry(self, decode, **fdopen_kwargs):

    (r, w) = os.pipe()
    fdopen_kwargs[u'closefd'] = False
    def alarm_handler(sig, frame):
        os.write(w, 'bar')
    signal.signal(signal.SIGALRM, alarm_handler)
    try:
        rio = self.io.open(r, **fdopen_kwargs)
        os.write(w, 'foo')
        signal.alarm(1)
        self.assertEqual(decode(rio.read(6)), u'foobar')
    finally:
        rio.close()
        os.close(w)
        os.close(r)
