sapling/eden/fs/utils/test/ProcessAccessLogTest.cpp
Chad Austin 4f532889d1 reenable ProcessNameCache
Summary:
Now that the deadlock in ProcessNameCache has been fixed, bring it
back.

Reviewed By: strager

Differential Revision: D13742965

fbshipit-source-id: f407105e06b9954766bdb48ef1303e2003c07284
2019-01-24 15:45:29 -08:00

46 lines
1.4 KiB
C++

/*
* Copyright (c) 2018-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "eden/fs/utils/ProcessAccessLog.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <sys/types.h>
#include <unistd.h>
#include <utility>
#include "eden/fs/utils/ProcessNameCache.h"
using ::testing::Contains;
using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::Key;
using namespace facebook::eden;
using namespace std::chrono_literals;
TEST(ProcessAccessLog, emptyLogHasNoAccesses) {
auto log = ProcessAccessLog{std::make_shared<ProcessNameCache>()};
EXPECT_THAT(log.getAllAccesses(1s), ElementsAre());
}
TEST(ProcessAccessLog, accessAddsProcessToProcessNameCache) {
auto pid = ::getpid();
auto processNameCache = std::make_shared<ProcessNameCache>();
auto log = ProcessAccessLog{processNameCache};
log.recordAccess(::getpid());
EXPECT_THAT(processNameCache->getAllProcessNames(), Contains(Key(Eq(pid))));
}
TEST(ProcessAccessLog, accessIncrementsAccessCount) {
auto pid = pid_t{42};
auto log = ProcessAccessLog{std::make_shared<ProcessNameCache>()};
log.recordAccess(pid);
log.recordAccess(pid);
log.recordAccess(pid);
EXPECT_THAT(log.getAllAccesses(1s), Contains(std::pair{pid, 3}));
}