Browse Source

Test: PityTest - AbstractPityUnit fix PROC_SEQ (added wait()), rename

master
heck 4 years ago
parent
commit
a0e6a0cfe3
  1. 65
      src/AbstractPityUnit.cc
  2. 14
      src/AbstractPityUnit.hh

65
src/AbstractPityUnit.cc

@ -91,13 +91,13 @@ namespace pEp {
if (isRoot()) { if (isRoot()) {
ret = getName(); ret = getName();
} else { } else {
if (_isProcessUnit()) { if (isProcessUnit()) {
ret += ".../" + getName(); ret += ".../" + getName();
} else { } else {
if (&(parentingProcessUnit()) == (getParent())) { if (&(getParentProcessUnit()) == (getParent())) {
ret = parentingProcessUnit().getPathShort() + "/" + getName(); ret = getParentProcessUnit().getPathShort() + "/" + getName();
} else { } else {
ret = parentingProcessUnit().getPathShort() + "/.../" + getName(); ret = getParentProcessUnit().getPathShort() + "/.../" + getName();
} }
} }
} }
@ -106,38 +106,30 @@ namespace pEp {
// Every process has its own dir inside its rootUnitDir // Every process has its own dir inside its rootUnitDir
// All other units inherit processDir from their Root/ProcessUnit // All other units inherit processDir from their Root/ProcessUnit
std::string AbstractPityUnit::processDir() std::string AbstractPityUnit::getProcessDir()
{ {
if (isRoot()) { if (isRoot()) {
return _rootUnitDir(); return getRootUnitDir();
} else { } else {
if (_isProcessUnit()) { if (isProcessUnit()) {
return _rootUnitDir() + getName() + "/"; return getGlobalRootDir() + _normalizeName(getPath()) + "/";
} else { } else {
return getParent()->processDir(); return getParent()->getProcessDir();
} }
} }
} }
// Every RootUnit has its own dir // Every RootUnit has its own dir
std::string AbstractPityUnit::_rootUnitDir() std::string AbstractPityUnit::getRootUnitDir()
{ {
return getGlobalRootDir() + getRoot().getName() + "/"; return getGlobalRootDir() + getRoot().getName() + "/";
} }
// Every process has its own dir inside its rootUnitDir // Every process has its own dir inside its rootUnitDir
// All other units inherit transportDir from their Root/ProcessUnit // All other units inherit transportDir from their Root/ProcessUnit
std::string AbstractPityUnit::transportDir() std::string AbstractPityUnit::getTransportDir()
{ {
if (isRoot()) { return getProcessDir() + "inbox/";
throw std::runtime_error("No transport dir");
} else {
if (_isProcessUnit()) {
return processDir() + "inbox/";
} else {
return getParent()->transportDir();
}
}
} }
void AbstractPityUnit::_initProcUnitNrRecurse() void AbstractPityUnit::_initProcUnitNrRecurse()
@ -146,7 +138,7 @@ namespace pEp {
// Inherit // Inherit
_procUnitNr = getParent()->_procUnitNr; _procUnitNr = getParent()->_procUnitNr;
//Or update if procUnit //Or update if procUnit
if (_isProcessUnit()) { if (isProcessUnit()) {
_procUnitsCount++; _procUnitsCount++;
_procUnitNr = _procUnitsCount; _procUnitNr = _procUnitsCount;
} }
@ -162,9 +154,9 @@ namespace pEp {
void AbstractPityUnit::_initTransportRecurse() void AbstractPityUnit::_initTransportRecurse()
{ {
logger_debug.set_instancename(getPath());
if (!isRoot()) { if (!isRoot()) {
if (_isProcessUnit()) { if (isProcessUnit()) {
_createTransport(); _createTransport();
} }
} }
@ -177,7 +169,7 @@ namespace pEp {
void AbstractPityUnit::_initDirsRecursive() void AbstractPityUnit::_initDirsRecursive()
{ {
Utils::dir_recreate(processDir()); Utils::dir_recreate(getProcessDir());
// Recurse // Recurse
for (const auto &child : getChildRefs()) { for (const auto &child : getChildRefs()) {
@ -200,6 +192,8 @@ namespace pEp {
_logRaw("Recreating process dirs recursively..."); _logRaw("Recreating process dirs recursively...");
_initDirsRecursive(); _initDirsRecursive();
//TODO:HACK wait for dir
Utils::sleep_millis(500);
_logRaw("Initializing Transport recursively..."); _logRaw("Initializing Transport recursively...");
_initTransportRecurse(); _initTransportRecurse();
@ -213,7 +207,7 @@ namespace pEp {
// TODO: hack // TODO: hack
setenv("HOME", processDir().c_str(), true); setenv("HOME", getProcessDir().c_str(), true);
// Execute in fork and wait here until process ends // Execute in fork and wait here until process ends
if (_exec_mode == ExecutionMode::PROCESS_SEQUENTIAL) { // fork if (_exec_mode == ExecutionMode::PROCESS_SEQUENTIAL) { // fork
@ -244,7 +238,7 @@ namespace pEp {
builder << getName(); builder << getName();
builder << " [ "; builder << " [ ";
builder << to_string(_exec_mode) << " - "; builder << to_string(_exec_mode) << " - ";
builder << "\"" << processDir() << "\""; builder << "\"" << getProcessDir() << "\"";
builder << " ]"; builder << " ]";
builder << std::endl; builder << std::endl;
ret = builder.str(); ret = builder.str();
@ -284,7 +278,7 @@ namespace pEp {
void AbstractPityUnit::registerAsTransportEndpoint() void AbstractPityUnit::registerAsTransportEndpoint()
{ {
transportEndpoints().insert({ getName(), transportDir() }); transportEndpoints().insert({ getName(), getTransportDir() });
} }
Endpoints &AbstractPityUnit::transportEndpoints() Endpoints &AbstractPityUnit::transportEndpoints()
@ -334,6 +328,9 @@ namespace pEp {
child.second.run(false); child.second.run(false);
} }
} }
// This should be fine
_waitChildProcesses();
} }
void AbstractPityUnit::_executeInFork(std::function<void(void)> func, bool wait_child) const void AbstractPityUnit::_executeInFork(std::function<void(void)> func, bool wait_child) const
@ -369,7 +366,7 @@ namespace pEp {
} }
} }
bool AbstractPityUnit::_isProcessUnit() const bool AbstractPityUnit::isProcessUnit() const
{ {
bool ret = false; bool ret = false;
if (_exec_mode == ExecutionMode::PROCESS_SEQUENTIAL || if (_exec_mode == ExecutionMode::PROCESS_SEQUENTIAL ||
@ -379,12 +376,12 @@ namespace pEp {
return ret; return ret;
} }
const AbstractPityUnit &AbstractPityUnit::parentingProcessUnit() const const AbstractPityUnit &AbstractPityUnit::getParentProcessUnit() const
{ {
if (isRoot() || _isProcessUnit()) { if (isRoot() || isProcessUnit()) {
return *this; return *this;
} else { } else {
return getParent()->parentingProcessUnit(); return getParent()->getParentProcessUnit();
} }
} }
@ -393,7 +390,7 @@ namespace pEp {
void AbstractPityUnit::_createTransport() void AbstractPityUnit::_createTransport()
{ {
registerAsTransportEndpoint(); registerAsTransportEndpoint();
_transport = std::make_shared<PityTransport>(transportDir(), transportEndpoints()); _transport = std::make_shared<PityTransport>(getTransportDir(), transportEndpoints());
} }
// Inherited (if null see parent recursively) // Inherited (if null see parent recursively)
@ -424,7 +421,7 @@ namespace pEp {
//static //static
Utils::Color AbstractPityUnit::_colForProcUnitNr(int procUnitNr) Utils::Color AbstractPityUnit::_colForProcUnitNr(int procUnitNr)
{ {
int nrColors = 7; int nrColors = 6;
switch (procUnitNr % nrColors) { switch (procUnitNr % nrColors) {
case 0: case 0:
return Utils::Color::WHITE; return Utils::Color::WHITE;
@ -438,8 +435,6 @@ namespace pEp {
return Utils::Color::BLUE; return Utils::Color::BLUE;
case 5: case 5:
return Utils::Color::MAGENTA; return Utils::Color::MAGENTA;
case 6:
return Utils::Color::RED;
default: default:
return Utils::Color::WHITE; return Utils::Color::WHITE;
} }

14
src/AbstractPityUnit.hh

@ -57,8 +57,12 @@ namespace pEp {
// Read-Only // Read-Only
std::string getPathShort() const; std::string getPathShort() const;
std::string processDir(); // own process dir std::string getProcessDir(); // own process dir
std::string transportDir(); std::string getTransportDir();
std::string getRootUnitDir();
bool isProcessUnit() const; // true if it forks
const AbstractPityUnit& getParentProcessUnit() const;
// Main funcs // Main funcs
void run(bool init_tree = true); void run(bool init_tree = true);
@ -102,12 +106,6 @@ namespace pEp {
void _executeInFork(std::function<void(void)> func, bool wait_child) const; void _executeInFork(std::function<void(void)> func, bool wait_child) const;
void _waitChildProcesses() const; void _waitChildProcesses() const;
const AbstractPityUnit& parentingProcessUnit() const;
// Query
bool _isProcessUnit() const; // true if it forks
std::string _rootUnitDir();
// Transport // Transport
void _createTransport(); void _createTransport();

Loading…
Cancel
Save