void WaitState(Porto::Connection &api, const std::string &name, const std::string &state, int sec) { Say() << "Waiting for " << name << " to be in state " << state << std::endl; int times = sec * 10; std::string ret; do { if (times-- <= 0) break; usleep(100000); (void)api.GetData(name, "state", ret); } while (ret != state); if (times <= 0) throw std::string("Waited too long for task to change state"); }
void TestDaemon(Porto::Connection &api) { struct dirent **lst; int pid; AsRoot(api); api.Close(); sleep(1); Say() << "Make sure portod-slave doesn't have zombies" << std::endl; pid = ReadPid(config().slave_pid().path()); ExpectEq(ChildrenNum(pid), 0); Say() << "Make sure portod-slave doesn't have invalid FDs" << std::endl; std::string path = ("/proc/" + std::to_string(pid) + "/fd"); // when sssd is running getgrnam opens unix socket to read database int sssFd = 0; if (WordCount("/etc/nsswitch.conf", "sss")) sssFd = 3; /** * . * .. * 0 (stdin) * 1 (stdout) * 128 (event pipe) * 129 (ack pipe) * 130 (rpc socket) * 2 (stderr) * 3 (portod.log) * 4 (epoll) * 5 (host netlink) * 6 (signalfd) */ int nr = scandir(path.c_str(), &lst, NULL, alphasort); PrintFds(path, lst, nr); ExpectLessEq(nr, 12 + sssFd); ExpectLessEq(12, nr); Say() << "Make sure portod-master doesn't have zombies" << std::endl; pid = ReadPid(config().master_pid().path()); ExpectEq(ChildrenNum(pid), 1); Say() << "Make sure portod-master doesn't have invalid FDs" << std::endl; Say() << "Number of portod-master fds=" << nr << std::endl; path = ("/proc/" + std::to_string(pid) + "/fd"); /** * . * .. * 0 (stdin) * 1 (stdout) * 130 (rpc socket) * 2 (stderr) * 3 (portoloop.log) * 4 (epoll) * 6 (event pipe) * 7 (ack pipe) * 9 (signalfd) */ nr = scandir(path.c_str(), &lst, NULL, alphasort); PrintFds(path, lst, nr); ExpectLessEq(nr, 11 + sssFd); ExpectLessEq(11, nr); Say() << "Check portod-master queue size" << std::endl; std::string v; ExpectApiSuccess(api.GetData("/", "porto_stat[queued_statuses]", v)); Expect(v == std::to_string(0)); Say() << "Check portod-slave queue size" << std::endl; ExpectApiSuccess(api.GetData("/", "porto_stat[queued_events]", v)); Expect(v != std::to_string(0)); // RotateLogs // TODO: check rtnl classes }