Make the fd cleanup test less brittle

PiperOrigin-RevId: 398229418
Change-Id: If8af43f33b07839ea8d46b85ff77efa8557a31a8
This commit is contained in:
Wiktor Garbacz 2021-09-22 06:57:15 -07:00 committed by Copybara-Service
parent b5fb483b11
commit b470a6ece5

View File

@ -173,12 +173,14 @@ TEST(SandboxTest, RestartSandboxFD) {
auto test_body = [](sapi::Sandbox* sandbox) -> absl::Status {
// Open some FDs and check their value.
EXPECT_THAT(LeakFileDescriptor(sandbox, "/proc/self/exe"), Eq(3));
EXPECT_THAT(LeakFileDescriptor(sandbox, "/proc/self/exe"), Eq(4));
int first_remote_fd = LeakFileDescriptor(sandbox, "/proc/self/exe");
EXPECT_THAT(LeakFileDescriptor(sandbox, "/proc/self/exe"),
Eq(first_remote_fd + 1));
SAPI_RETURN_IF_ERROR(sandbox->Restart(false));
// We should have a fresh sandbox now = FDs open previously should be
// closed now.
EXPECT_THAT(LeakFileDescriptor(sandbox, "/proc/self/exe"), Eq(3));
EXPECT_THAT(LeakFileDescriptor(sandbox, "/proc/self/exe"),
Eq(first_remote_fd));
return absl::OkStatus();
};