From a0e6a0cfe384324718eceb6d740a3959b4ba5d1c Mon Sep 17 00:00:00 2001 From: heck Date: Sat, 10 Jul 2021 16:38:34 +0200 Subject: [PATCH] Test: PityTest - AbstractPityUnit fix PROC_SEQ (added wait()), rename --- src/AbstractPityUnit.cc | 65 +++++++++++++++++++---------------------- src/AbstractPityUnit.hh | 14 ++++----- 2 files changed, 36 insertions(+), 43 deletions(-) diff --git a/src/AbstractPityUnit.cc b/src/AbstractPityUnit.cc index b737e47..b504384 100644 --- a/src/AbstractPityUnit.cc +++ b/src/AbstractPityUnit.cc @@ -91,13 +91,13 @@ namespace pEp { if (isRoot()) { ret = getName(); } else { - if (_isProcessUnit()) { + if (isProcessUnit()) { ret += ".../" + getName(); } else { - if (&(parentingProcessUnit()) == (getParent())) { - ret = parentingProcessUnit().getPathShort() + "/" + getName(); + if (&(getParentProcessUnit()) == (getParent())) { + ret = getParentProcessUnit().getPathShort() + "/" + getName(); } else { - ret = parentingProcessUnit().getPathShort() + "/.../" + getName(); + ret = getParentProcessUnit().getPathShort() + "/.../" + getName(); } } } @@ -106,38 +106,30 @@ namespace pEp { // Every process has its own dir inside its rootUnitDir // All other units inherit processDir from their Root/ProcessUnit - std::string AbstractPityUnit::processDir() + std::string AbstractPityUnit::getProcessDir() { if (isRoot()) { - return _rootUnitDir(); + return getRootUnitDir(); } else { - if (_isProcessUnit()) { - return _rootUnitDir() + getName() + "/"; + if (isProcessUnit()) { + return getGlobalRootDir() + _normalizeName(getPath()) + "/"; } else { - return getParent()->processDir(); + return getParent()->getProcessDir(); } } } // Every RootUnit has its own dir - std::string AbstractPityUnit::_rootUnitDir() + std::string AbstractPityUnit::getRootUnitDir() { return getGlobalRootDir() + getRoot().getName() + "/"; } // Every process has its own dir inside its rootUnitDir // All other units inherit transportDir from their Root/ProcessUnit - std::string AbstractPityUnit::transportDir() + std::string AbstractPityUnit::getTransportDir() { - if (isRoot()) { - throw std::runtime_error("No transport dir"); - } else { - if (_isProcessUnit()) { - return processDir() + "inbox/"; - } else { - return getParent()->transportDir(); - } - } + return getProcessDir() + "inbox/"; } void AbstractPityUnit::_initProcUnitNrRecurse() @@ -146,7 +138,7 @@ namespace pEp { // Inherit _procUnitNr = getParent()->_procUnitNr; //Or update if procUnit - if (_isProcessUnit()) { + if (isProcessUnit()) { _procUnitsCount++; _procUnitNr = _procUnitsCount; } @@ -162,9 +154,9 @@ namespace pEp { void AbstractPityUnit::_initTransportRecurse() { - logger_debug.set_instancename(getPath()); + if (!isRoot()) { - if (_isProcessUnit()) { + if (isProcessUnit()) { _createTransport(); } } @@ -177,7 +169,7 @@ namespace pEp { void AbstractPityUnit::_initDirsRecursive() { - Utils::dir_recreate(processDir()); + Utils::dir_recreate(getProcessDir()); // Recurse for (const auto &child : getChildRefs()) { @@ -200,6 +192,8 @@ namespace pEp { _logRaw("Recreating process dirs recursively..."); _initDirsRecursive(); + //TODO:HACK wait for dir + Utils::sleep_millis(500); _logRaw("Initializing Transport recursively..."); _initTransportRecurse(); @@ -213,7 +207,7 @@ namespace pEp { // TODO: hack - setenv("HOME", processDir().c_str(), true); + setenv("HOME", getProcessDir().c_str(), true); // Execute in fork and wait here until process ends if (_exec_mode == ExecutionMode::PROCESS_SEQUENTIAL) { // fork @@ -244,7 +238,7 @@ namespace pEp { builder << getName(); builder << " [ "; builder << to_string(_exec_mode) << " - "; - builder << "\"" << processDir() << "\""; + builder << "\"" << getProcessDir() << "\""; builder << " ]"; builder << std::endl; ret = builder.str(); @@ -284,7 +278,7 @@ namespace pEp { void AbstractPityUnit::registerAsTransportEndpoint() { - transportEndpoints().insert({ getName(), transportDir() }); + transportEndpoints().insert({ getName(), getTransportDir() }); } Endpoints &AbstractPityUnit::transportEndpoints() @@ -334,6 +328,9 @@ namespace pEp { child.second.run(false); } } + + // This should be fine + _waitChildProcesses(); } void AbstractPityUnit::_executeInFork(std::function func, bool wait_child) const @@ -369,7 +366,7 @@ namespace pEp { } } - bool AbstractPityUnit::_isProcessUnit() const + bool AbstractPityUnit::isProcessUnit() const { bool ret = false; if (_exec_mode == ExecutionMode::PROCESS_SEQUENTIAL || @@ -379,12 +376,12 @@ namespace pEp { return ret; } - const AbstractPityUnit &AbstractPityUnit::parentingProcessUnit() const + const AbstractPityUnit &AbstractPityUnit::getParentProcessUnit() const { - if (isRoot() || _isProcessUnit()) { + if (isRoot() || isProcessUnit()) { return *this; } else { - return getParent()->parentingProcessUnit(); + return getParent()->getParentProcessUnit(); } } @@ -393,7 +390,7 @@ namespace pEp { void AbstractPityUnit::_createTransport() { registerAsTransportEndpoint(); - _transport = std::make_shared(transportDir(), transportEndpoints()); + _transport = std::make_shared(getTransportDir(), transportEndpoints()); } // Inherited (if null see parent recursively) @@ -424,7 +421,7 @@ namespace pEp { //static Utils::Color AbstractPityUnit::_colForProcUnitNr(int procUnitNr) { - int nrColors = 7; + int nrColors = 6; switch (procUnitNr % nrColors) { case 0: return Utils::Color::WHITE; @@ -438,8 +435,6 @@ namespace pEp { return Utils::Color::BLUE; case 5: return Utils::Color::MAGENTA; - case 6: - return Utils::Color::RED; default: return Utils::Color::WHITE; } diff --git a/src/AbstractPityUnit.hh b/src/AbstractPityUnit.hh index 335593c..4c6b944 100644 --- a/src/AbstractPityUnit.hh +++ b/src/AbstractPityUnit.hh @@ -57,8 +57,12 @@ namespace pEp { // Read-Only std::string getPathShort() const; - std::string processDir(); // own process dir - std::string transportDir(); + std::string getProcessDir(); // own process dir + std::string getTransportDir(); + std::string getRootUnitDir(); + bool isProcessUnit() const; // true if it forks + const AbstractPityUnit& getParentProcessUnit() const; + // Main funcs void run(bool init_tree = true); @@ -102,12 +106,6 @@ namespace pEp { void _executeInFork(std::function func, bool wait_child) const; void _waitChildProcesses() const; - const AbstractPityUnit& parentingProcessUnit() const; - - // Query - bool _isProcessUnit() const; // true if it forks - std::string _rootUnitDir(); - // Transport void _createTransport();