2019-05-29 07:36:37 +03:00
|
|
|
/*
|
2019-06-20 02:58:25 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2019-05-29 07:36:37 +03:00
|
|
|
*
|
2019-06-20 02:58:25 +03:00
|
|
|
* This software may be used and distributed according to the terms of the
|
|
|
|
* GNU General Public License version 2.
|
2019-05-29 07:36:37 +03:00
|
|
|
*/
|
2019-10-11 15:26:59 +03:00
|
|
|
|
2019-05-29 07:36:37 +03:00
|
|
|
#include "eden/fs/testharness/TestServer.h"
|
|
|
|
|
|
|
|
#include <folly/portability/GFlags.h>
|
|
|
|
|
|
|
|
#include "eden/fs/config/EdenConfig.h"
|
|
|
|
#include "eden/fs/service/EdenServer.h"
|
|
|
|
#include "eden/fs/service/StartupLogger.h"
|
2019-11-14 02:21:37 +03:00
|
|
|
#include "eden/fs/telemetry/SessionInfo.h"
|
2019-05-29 07:36:37 +03:00
|
|
|
#include "eden/fs/testharness/FakePrivHelper.h"
|
|
|
|
#include "eden/fs/testharness/TempFile.h"
|
2020-04-30 03:16:28 +03:00
|
|
|
#include "eden/fs/utils/UserInfo.h"
|
2019-05-29 07:36:37 +03:00
|
|
|
|
|
|
|
using std::make_shared;
|
|
|
|
using std::make_unique;
|
|
|
|
using std::unique_ptr;
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
|
|
|
TestServer::TestServer()
|
|
|
|
: tmpDir_(makeTempDir()), server_(createServer(getTmpDir())) {
|
|
|
|
auto prepareResult = server_->prepare(make_shared<ForegroundStartupLogger>());
|
|
|
|
// We don't care about waiting for prepareResult: it just indicates when
|
|
|
|
// preparation has fully completed, but the EdenServer can begin being used
|
|
|
|
// immediately, before prepareResult completes.
|
|
|
|
//
|
|
|
|
// Maybe in the future it would be worth storing this future in a member
|
|
|
|
// variable so our caller could extract if if they want to. (It would allow
|
|
|
|
// the caller to schedule additional work once the thrift server is fully up
|
|
|
|
// and running, if the caller starts the thrift server.)
|
|
|
|
(void)prepareResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
TestServer::~TestServer() {}
|
|
|
|
|
|
|
|
AbsolutePath TestServer::getTmpDir() const {
|
|
|
|
return AbsolutePath{tmpDir_.path().string()};
|
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<EdenServer> TestServer::createServer(AbsolutePathPiece tmpDir) {
|
|
|
|
auto edenDir = tmpDir + "eden"_pc;
|
|
|
|
ensureDirectoryExists(edenDir);
|
|
|
|
|
|
|
|
// Always use an in-memory local store during tests.
|
|
|
|
// TODO: in the future we should build a better mechanism for controlling this
|
|
|
|
// rather than having to update a command line flag.
|
|
|
|
GFLAGS_NAMESPACE::SetCommandLineOptionWithMode(
|
|
|
|
"local_storage_engine_unsafe",
|
|
|
|
"memory",
|
|
|
|
GFLAGS_NAMESPACE::SET_FLAG_IF_DEFAULT);
|
|
|
|
|
|
|
|
auto userInfo = UserInfo::lookup();
|
|
|
|
userInfo.setHomeDirectory(tmpDir + "home"_pc);
|
|
|
|
auto config = make_shared<EdenConfig>(
|
|
|
|
userInfo.getUsername(),
|
|
|
|
userInfo.getUid(),
|
|
|
|
userInfo.getHomeDirectory(),
|
|
|
|
userInfo.getHomeDirectory() + ".edenrc"_pc,
|
|
|
|
tmpDir + "etc"_pc,
|
|
|
|
tmpDir + "etc/edenfs.rc"_relpath);
|
|
|
|
auto privHelper = make_unique<FakePrivHelper>();
|
2019-10-12 03:53:48 +03:00
|
|
|
config->edenDir.setValue(edenDir, ConfigSource::CommandLine);
|
2019-05-29 07:36:37 +03:00
|
|
|
|
2019-07-17 23:43:32 +03:00
|
|
|
return make_unique<EdenServer>(
|
|
|
|
std::vector<std::string>{"edenfs_unit_test"},
|
|
|
|
userInfo,
|
2019-11-14 02:21:37 +03:00
|
|
|
SessionInfo{},
|
2019-07-17 23:43:32 +03:00
|
|
|
std::move(privHelper),
|
2019-10-24 22:46:59 +03:00
|
|
|
config,
|
|
|
|
"test server");
|
2019-05-29 07:36:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|