mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Close FD on TcpSocketTest loop failure.
This helps prevent the blocking call from getting stuck and causing a test timeout. PiperOrigin-RevId: 254325926
This commit is contained in:
@@ -265,10 +265,16 @@ TEST_P(TcpSocketTest, BlockingLargeWrite_NoRandomSave) {
|
||||
ScopedThread t([this, &read_bytes]() {
|
||||
// Avoid interrupting the blocking write in main thread.
|
||||
const DisableSave ds;
|
||||
|
||||
// Take ownership of the FD so that we close it on failure. This will
|
||||
// unblock the blocking write below.
|
||||
FileDescriptor fd(t_);
|
||||
t_ = -1;
|
||||
|
||||
char readbuf[2500] = {};
|
||||
int n = -1;
|
||||
while (n != 0) {
|
||||
ASSERT_THAT(n = RetryEINTR(read)(t_, &readbuf, sizeof(readbuf)),
|
||||
ASSERT_THAT(n = RetryEINTR(read)(fd.get(), &readbuf, sizeof(readbuf)),
|
||||
SyscallSucceeds());
|
||||
read_bytes += n;
|
||||
}
|
||||
@@ -342,10 +348,16 @@ TEST_P(TcpSocketTest, BlockingLargeSend_NoRandomSave) {
|
||||
ScopedThread t([this, &read_bytes]() {
|
||||
// Avoid interrupting the blocking write in main thread.
|
||||
const DisableSave ds;
|
||||
|
||||
// Take ownership of the FD so that we close it on failure. This will
|
||||
// unblock the blocking write below.
|
||||
FileDescriptor fd(t_);
|
||||
t_ = -1;
|
||||
|
||||
char readbuf[2500] = {};
|
||||
int n = -1;
|
||||
while (n != 0) {
|
||||
ASSERT_THAT(n = RetryEINTR(read)(t_, &readbuf, sizeof(readbuf)),
|
||||
ASSERT_THAT(n = RetryEINTR(read)(fd.get(), &readbuf, sizeof(readbuf)),
|
||||
SyscallSucceeds());
|
||||
read_bytes += n;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user