tst_QProcess::startStopStartStopBuffers: depend less on OS configuration
The comment in this function made it clear that it really depended on the size of the pipe buffer in the OS. I don't see a way to make a pipe default to a different size on Linux -- it always defaults to PIPE_DEF_BUFFERS (16) and that value is only increased as a result of fcntl(F_SETPIPE_SZ), which we don't do. But we can be defensive and simply write until the OS can't take any more data. Drive-by update the comment on Windows to be clear that bytesToWrite() does work, but only while the child process is still running. Pick-to: 6.6 Task-number: QTBUG-80953 Change-Id: I9d43e5b91eb142d6945cfffd17866d22a4127e5e Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
5a2aa12147
commit
a3f2ddc230
@ -2889,14 +2889,18 @@ void tst_QProcess::startStopStartStopBuffers()
|
||||
}
|
||||
|
||||
// We want to test that the write buffer still has bytes after the child
|
||||
// exiting. We do that by writing to a child process that never reads. We
|
||||
// just have to write more data than a pipe can hold, so that even if
|
||||
// QProcess finds the pipe writable (during waitForFinished() or in the
|
||||
// QWindowsPipeWriter thread), some data will remain. The worst case I know
|
||||
// of is Linux, which defaults to 64 kB of buffer.
|
||||
// exits. We can do that by writing data until the OS stops consuming data,
|
||||
// indicating that the pipe buffers are full. The initial value of 128 kB
|
||||
// should make this loop typicall run only once; the worst case I know of
|
||||
// is Linux, which defaults to 64 kB of buffer.
|
||||
|
||||
process.write(QByteArray(128 * 1024, 'a'));
|
||||
QVERIFY(process.bytesToWrite() > 0);
|
||||
QByteArray chunk(128 * 1024, 'a');
|
||||
do {
|
||||
process.write(chunk);
|
||||
QVERIFY(process.bytesToWrite() > 0);
|
||||
process.waitForBytesWritten(1);
|
||||
} while (process.bytesToWrite() == 0);
|
||||
chunk = {};
|
||||
process.kill();
|
||||
|
||||
QVERIFY(process.waitForFinished());
|
||||
@ -2904,7 +2908,8 @@ void tst_QProcess::startStopStartStopBuffers()
|
||||
#ifndef Q_OS_WIN
|
||||
// confirm that our buffers are still full
|
||||
// Note: this doesn't work on Windows because our buffers are drained into
|
||||
// QWindowsPipeWriter before being sent to the child process.
|
||||
// QWindowsPipeWriter before being sent to the child process and are lost
|
||||
// in waitForFinished() -> processFinished() -> cleanup().
|
||||
QVERIFY(process.bytesToWrite() > 0);
|
||||
QVERIFY(process.bytesAvailable() > 0); // channelMode1 is not ForwardedChannels
|
||||
if (channelMode1 == QProcess::SeparateChannels || channelMode1 == QProcess::ForwardedOutputChannel) {
|
||||
|
Loading…
Reference in New Issue
Block a user