mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
4f532889d1
Summary: Now that the deadlock in ProcessNameCache has been fixed, bring it back. Reviewed By: strager Differential Revision: D13742965 fbshipit-source-id: f407105e06b9954766bdb48ef1303e2003c07284
46 lines
1.4 KiB
C++
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}));
|
|
}
|