'Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/150
This is similar to test_update_resized_header, but specifically tests a
case of multiple consecutive flush() calls on the same HDUList object,
where each flush() requires a resize.'

def test_update_resized_header2(self):

    data1 = np.arange(100)
    data2 = (np.arange(100) + 100)
    phdu = fits.PrimaryHDU(data=data1)
    hdu = fits.ImageHDU(data=data2)
    phdu.writeto(self.temp('temp.fits'))
    with fits.open(self.temp('temp.fits'), mode='append') as hdul:
        hdul.append(hdu)
    with fits.open(self.temp('temp.fits'), mode='update') as hdul:
        idx = 1
        while (len(str(hdul[0].header)) <= (2880 * 2)):
            hdul[0].header['TEST{}'.format(idx)] = idx
            idx += 1
        hdul.flush()
        hdul.append(hdu)
    with fits.open(self.temp('temp.fits')) as hdul:
        assert (hdul[0].data == data1).all()
        assert (hdul[1].header == hdu.header)
        assert (hdul[1].data == data2).all()
        assert (hdul[2].data == data2).all()
