From b470a6ece5cf87bd3bc15649bdc7c902c29e3c5a Mon Sep 17 00:00:00 2001 From: Wiktor Garbacz Date: Wed, 22 Sep 2021 06:57:15 -0700 Subject: [PATCH] Make the fd cleanup test less brittle PiperOrigin-RevId: 398229418 Change-Id: If8af43f33b07839ea8d46b85ff77efa8557a31a8 --- sandboxed_api/sapi_test.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sandboxed_api/sapi_test.cc b/sandboxed_api/sapi_test.cc index d440c7b..d8a42eb 100644 --- a/sandboxed_api/sapi_test.cc +++ b/sandboxed_api/sapi_test.cc @@ -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(); };