Skip to content

Commit

Permalink
testharness: remove QueuedImmediateExecutor from TestMount
Browse files Browse the repository at this point in the history
Summary:
We can merely change the code to use ImmediateFuture and let the callsite
(tests) attach the server executor to it if needed.

Reviewed By: genevievehelsel

Differential Revision: D50415723

fbshipit-source-id: 5edc144b5e54a2c29afe686a57bd60c370d57292
  • Loading branch information
xavierd authored and facebook-github-bot committed Oct 24, 2023
1 parent ef62822 commit 07e29c3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
1 change: 0 additions & 1 deletion eden/fs/testharness/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ cpp_library(
"//eden/fs/utils:user_info",
"//eden/fs/utils:utils",
"//folly:file_util",
"//folly/executors:queued_immediate_executor",
"//folly/experimental:test_util",
"//folly/io:iobuf",
"//folly/logging:logging",
Expand Down
20 changes: 8 additions & 12 deletions eden/fs/testharness/TestMount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <folly/FileUtil.h>
#include <folly/executors/ManualExecutor.h>
#include <folly/executors/QueuedImmediateExecutor.h>
#include <folly/experimental/TestUtil.h>
#include <folly/io/IOBuf.h>
#include <folly/logging/xlog.h>
Expand Down Expand Up @@ -54,8 +53,6 @@
#include "eden/fs/utils/UnboundedQueueExecutor.h"
#include "eden/fs/utils/UserInfo.h"

using folly::Future;
using folly::makeFuture;
using folly::Unit;
using namespace std::chrono_literals;
using namespace std::string_literals;
Expand Down Expand Up @@ -835,20 +832,21 @@ VirtualInode TestMount::getVirtualInode(folly::StringPiece path) const {
}

void TestMount::loadAllInodes() {
auto fut = loadAllInodesFuture().via(getServerExecutor().get());
auto fut = loadAllInodesFuture().semi().via(getServerExecutor().get());
drainServerExecutor();
std::move(fut).get(std::chrono::milliseconds(1));
}

Future<Unit> TestMount::loadAllInodesFuture() {
ImmediateFuture<Unit> TestMount::loadAllInodesFuture() {
return loadAllInodesFuture(edenMount_->getRootInode());
}

void TestMount::loadAllInodes(const TreeInodePtr& treeInode) {
loadAllInodesFuture(treeInode).get();
}

Future<Unit> TestMount::loadAllInodesFuture(const TreeInodePtr& treeInode) {
ImmediateFuture<Unit> TestMount::loadAllInodesFuture(
const TreeInodePtr& treeInode) {
// Build a list of child names to load.
// (If necessary we could make a more efficient version of this that starts
// all the child loads while holding the lock. However, we don't really care
Expand All @@ -862,22 +860,20 @@ Future<Unit> TestMount::loadAllInodesFuture(const TreeInodePtr& treeInode) {
}

// Now start all the loads.
std::vector<Future<Unit>> childFutures;
std::vector<ImmediateFuture<Unit>> childFutures;
for (const auto& name : childNames) {
auto childFuture =
treeInode->getOrLoadChild(name, ObjectFetchContext::getNullContext())
.semi()
.via(&folly::QueuedImmediateExecutor::instance())
.thenValue([](InodePtr child) {
.thenValue([](InodePtr child) -> ImmediateFuture<folly::Unit> {
TreeInodePtr childTree = child.asTreePtrOrNull();
if (childTree) {
return loadAllInodesFuture(childTree);
}
return makeFuture();
return folly::unit;
});
childFutures.emplace_back(std::move(childFuture));
}
return folly::collectUnsafe(childFutures).unit();
return collectAllSafe(std::move(childFutures)).unit();
}

std::shared_ptr<const Tree> TestMount::getRootTree() const {
Expand Down
6 changes: 2 additions & 4 deletions eden/fs/testharness/TestMount.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include "eden/fs/utils/PathFuncs.h"

namespace folly {
template <typename T>
class Future;
struct Unit;
class ManualExecutor;

Expand Down Expand Up @@ -314,13 +312,13 @@ class TestMount {
* Walk the entire tree and load all inode objects.
*/
void loadAllInodes();
FOLLY_NODISCARD folly::Future<folly::Unit> loadAllInodesFuture();
FOLLY_NODISCARD ImmediateFuture<folly::Unit> loadAllInodesFuture();

/**
* Load all inodes [recursively] under the specified subdirectory.
*/
static void loadAllInodes(const TreeInodePtr& treeInode);
FOLLY_NODISCARD static folly::Future<folly::Unit> loadAllInodesFuture(
FOLLY_NODISCARD static ImmediateFuture<folly::Unit> loadAllInodesFuture(
const TreeInodePtr& treeInode);

/** Convenience method for getting the Tree for the root of the mount. */
Expand Down

0 comments on commit 07e29c3

Please sign in to comment.