Move kit pid helper functions to one file
Signed-off-by: Neil Guertin <neil.guertin@collabora.com> Change-Id: If77b8ac3c7493f4d44b510ec54b68292856f89d5pull/8503/head
parent
a40be5499e
commit
f82915ebcb
|
@ -378,7 +378,7 @@ noinst_HEADERS = $(wsd_headers) $(shared_headers) $(kit_headers) \
|
|||
test/UnitHTTP.hpp \
|
||||
test/HttpTestServer.hpp \
|
||||
test/WopiTestServer.hpp \
|
||||
test/countcoolkits.hpp \
|
||||
test/KitPidHelpers.hpp \
|
||||
test/lokassert.hpp \
|
||||
test/test.hpp \
|
||||
test/testlog.hpp \
|
||||
|
|
|
@ -8,29 +8,47 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
#include "KitPidHelpers.hpp"
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <set>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include <Poco/DirectoryIterator.h>
|
||||
#include <Poco/FileStream.h>
|
||||
#include <Poco/StreamCopier.h>
|
||||
|
||||
#include <wsd/COOLWSD.hpp>
|
||||
#include <Common.hpp>
|
||||
#include "Util.hpp"
|
||||
#include "lokassert.hpp"
|
||||
#include "test.hpp"
|
||||
#include "testlog.hpp"
|
||||
#include <Util.hpp>
|
||||
|
||||
static int countCoolKitProcesses(const int expected,
|
||||
std::chrono::milliseconds timeoutMs
|
||||
= std::chrono::milliseconds(COMMAND_TIMEOUT_MS * 8))
|
||||
#include <lokassert.hpp>
|
||||
#include <test.hpp>
|
||||
#include <testlog.hpp>
|
||||
|
||||
std::string getPidList(std::set<pid_t> pids);
|
||||
|
||||
std::set<pid_t> helpers::getKitPids() { return COOLWSD::getKitPids(); }
|
||||
|
||||
std::set<pid_t> helpers::getSpareKitPids() { return COOLWSD::getSpareKitPids(); }
|
||||
|
||||
std::set<pid_t> helpers::getDocKitPids() { return COOLWSD::getDocKitPids(); }
|
||||
|
||||
/// Get the PID of the forkit
|
||||
std::set<pid_t> helpers::getForKitPids()
|
||||
{
|
||||
std::set<pid_t> pids;
|
||||
if (COOLWSD::ForKitProcId >= 0)
|
||||
pids.emplace(COOLWSD::ForKitProcId);
|
||||
return pids;
|
||||
}
|
||||
|
||||
/// How many live coolkit processes do we have ?
|
||||
int helpers::getCoolKitProcessCount()
|
||||
{
|
||||
return getKitPids().size();
|
||||
}
|
||||
|
||||
int helpers::countCoolKitProcesses(const int expected)
|
||||
{
|
||||
std::chrono::milliseconds timeoutMs = std::chrono::milliseconds(COMMAND_TIMEOUT_MS) * 8;
|
||||
const auto testname = "countCoolKitProcesses ";
|
||||
TST_LOG_BEGIN("Waiting until coolkit processes are exactly " << expected << ". Coolkits: ");
|
||||
|
||||
|
@ -64,6 +82,7 @@ static int countCoolKitProcesses(const int expected,
|
|||
}
|
||||
|
||||
TST_LOG_END;
|
||||
LOK_ASSERT(expected == count);
|
||||
if (expected != count)
|
||||
{
|
||||
TST_LOG_BEGIN("Found " << count << " LoKit processes but was expecting " << expected << ": [");
|
||||
|
@ -87,37 +106,69 @@ static int countCoolKitProcesses(const int expected,
|
|||
return count;
|
||||
}
|
||||
|
||||
// FIXME: we probably should make this extern
|
||||
// and reuse it. As it stands now, it is per
|
||||
// translation unit, which isn't desirable if
|
||||
// (in the non-ideal event that) it's not 1,
|
||||
// it will cause testNoExtraCoolKitsLeft to
|
||||
// wait unnecessarily and fail.
|
||||
static int InitialCoolKitCount = 1;
|
||||
static std::chrono::steady_clock::time_point TestStartTime;
|
||||
|
||||
static void testCountHowManyCoolkits()
|
||||
void helpers::testCountHowManyCoolkits()
|
||||
{
|
||||
const char testname[] = "countHowManyCoolkits ";
|
||||
TestStartTime = std::chrono::steady_clock::now();
|
||||
resetTestStartTime();
|
||||
|
||||
InitialCoolKitCount = countCoolKitProcesses(InitialCoolKitCount);
|
||||
countCoolKitProcesses(InitialCoolKitCount);
|
||||
TST_LOG("Initial coolkit count is " << InitialCoolKitCount);
|
||||
LOK_ASSERT(InitialCoolKitCount > 0);
|
||||
|
||||
TestStartTime = std::chrono::steady_clock::now();
|
||||
resetTestStartTime();
|
||||
}
|
||||
|
||||
static void testNoExtraCoolKitsLeft()
|
||||
void helpers::testNoExtraCoolKitsLeft()
|
||||
{
|
||||
const char testname[] = "noExtraCoolKitsLeft ";
|
||||
const int countNow = countCoolKitProcesses(InitialCoolKitCount);
|
||||
LOK_ASSERT_EQUAL(InitialCoolKitCount, countNow);
|
||||
|
||||
const auto duration = (std::chrono::steady_clock::now() - TestStartTime);
|
||||
const auto durationMs = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
|
||||
const auto durationMs = timeSinceTestStartMs();
|
||||
|
||||
TST_LOG(" (" << durationMs << ')');
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
void helpers::waitForKitProcessToStop(
|
||||
const pid_t pid,
|
||||
const std::string& testname,
|
||||
const std::chrono::milliseconds timeoutMs /* = COMMAND_TIMEOUT_MS * 8 */,
|
||||
const std::chrono::milliseconds retryMs /* = 10ms */)
|
||||
{
|
||||
TST_LOG("Waiting for kit process " << pid << " to stop.");
|
||||
|
||||
std::set<pid_t> pids = getDocKitPids();
|
||||
TST_LOG("Active kit pids are: " << getPidList(pids));
|
||||
|
||||
int tries = (timeoutMs / retryMs);
|
||||
while(pids.contains(pid) && tries >= 0)
|
||||
{
|
||||
std::this_thread::sleep_for(retryMs);
|
||||
pids = getDocKitPids();
|
||||
tries--;
|
||||
}
|
||||
|
||||
if (pids.contains(pid))
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Timed out waiting for kit process " << pid << " to stop. Active kit pids are: " << getPidList(pids);
|
||||
LOK_ASSERT_FAIL(oss.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
TST_LOG("Finished waiting for kit process " << pid << " to stop.");
|
||||
TST_LOG("Active kit pids are: " << getPidList(pids));
|
||||
}
|
||||
}
|
||||
|
||||
std::string getPidList(std::set<pid_t> pids)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "[";
|
||||
for (pid_t i : pids)
|
||||
{
|
||||
oss << i << ", ";
|
||||
}
|
||||
oss << "]";
|
||||
return oss.str();
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
||||
/*
|
||||
* Copyright the Collabora Online contributors.
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <set>
|
||||
|
||||
#include <Common.hpp>
|
||||
|
||||
namespace helpers
|
||||
{
|
||||
|
||||
const int InitialCoolKitCount = 1;
|
||||
void testCountHowManyCoolkits();
|
||||
void testNoExtraCoolKitsLeft();
|
||||
|
||||
int countCoolKitProcesses(const int expected);/*,
|
||||
std::chrono::milliseconds timeoutMs
|
||||
= std::chrono::milliseconds(COMMAND_TIMEOUT_MS * 8));
|
||||
*/
|
||||
|
||||
/// Get the list of all kit PIDs
|
||||
std::set<pid_t> getKitPids();
|
||||
/// Get the list of spare (unused) kit PIDs
|
||||
std::set<pid_t> getSpareKitPids();
|
||||
/// Get the list of doc (loaded) kit PIDs
|
||||
std::set<pid_t> getDocKitPids();
|
||||
|
||||
/// Get the PID of the forkit
|
||||
std::set<pid_t> getForKitPids();
|
||||
|
||||
/// How many live coolkit processes do we have ?
|
||||
int getCoolKitProcessCount();
|
||||
|
||||
void waitForKitProcessToStop(
|
||||
const pid_t pid,
|
||||
const std::string& testname,
|
||||
const std::chrono::milliseconds timeoutMs = std::chrono::milliseconds(COMMAND_TIMEOUT_MS * 8),
|
||||
const std::chrono::milliseconds retryMs = std::chrono::milliseconds(10));
|
||||
|
||||
}
|
|
@ -183,13 +183,13 @@ fakesockettest_LDADD = $(CPPUNIT_LIBS)
|
|||
|
||||
# old-style unit tests - bootstrapped via UnitClient
|
||||
unit_base_la_SOURCES = UnitClient.cpp ${test_base_sources}
|
||||
unit_tiletest_la_SOURCES = UnitClient.cpp TileCacheTests.cpp
|
||||
unit_tiletest_la_SOURCES = UnitClient.cpp TileCacheTests.cpp KitPidHelpers.cpp
|
||||
unit_tiletest_la_LIBADD = $(CPPUNIT_LIBS)
|
||||
unit_integration_la_SOURCES = UnitClient.cpp integration-http-server.cpp
|
||||
unit_integration_la_SOURCES = UnitClient.cpp integration-http-server.cpp KitPidHelpers.cpp
|
||||
unit_integration_la_LIBADD = $(CPPUNIT_LIBS)
|
||||
unit_httpws_la_SOURCES = UnitClient.cpp httpwstest.cpp
|
||||
unit_httpws_la_SOURCES = UnitClient.cpp httpwstest.cpp KitPidHelpers.cpp
|
||||
unit_httpws_la_LIBADD = $(CPPUNIT_LIBS)
|
||||
unit_crash_la_SOURCES = UnitClient.cpp httpcrashtest.cpp
|
||||
unit_crash_la_SOURCES = UnitClient.cpp httpcrashtest.cpp KitPidHelpers.cpp
|
||||
unit_crash_la_LIBADD = $(CPPUNIT_LIBS)
|
||||
|
||||
# unit test modules:
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
|
||||
#include "WebSocketSession.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
|
||||
#include <Poco/Net/AcceptCertificateHandler.h>
|
||||
#include <Poco/Net/InvalidCertificateHandler.h>
|
||||
#include <Poco/Net/SSLManager.h>
|
||||
|
@ -28,11 +31,9 @@
|
|||
#include <Unit.hpp>
|
||||
#include <Util.hpp>
|
||||
|
||||
#include <countcoolkits.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <test.hpp>
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
#include <KitPidHelpers.hpp>
|
||||
|
||||
using namespace helpers;
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
#include <test/testlog.hpp>
|
||||
#include <test/lokassert.hpp>
|
||||
#include <test/test.hpp>
|
||||
|
||||
#include <Poco/BinaryReader.h>
|
||||
#include <Poco/Dynamic/Var.h>
|
||||
|
@ -951,53 +950,6 @@ inline std::string getAllText(const std::shared_ptr<http::WebSocketSession>& soc
|
|||
return std::string();
|
||||
}
|
||||
|
||||
|
||||
inline std::string getPidList(std::set<pid_t> pids)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "[";
|
||||
for (pid_t i : pids)
|
||||
{
|
||||
oss << i << ", ";
|
||||
}
|
||||
oss << "]";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
inline void waitForKitProcessToStop(
|
||||
const pid_t pid,
|
||||
const std::string& testname,
|
||||
const std::chrono::milliseconds timeoutMs = std::chrono::milliseconds(COMMAND_TIMEOUT_MS * 8),
|
||||
const std::chrono::milliseconds retryMs = std::chrono::milliseconds(10))
|
||||
{
|
||||
|
||||
TST_LOG("Waiting for kit process " << pid << " to stop.");
|
||||
|
||||
std::set<pid_t> pids = getDocKitPids();
|
||||
TST_LOG("Active kit pids are: " << getPidList(pids));
|
||||
|
||||
int tries = (timeoutMs / retryMs);
|
||||
while(pids.contains(pid) && tries >= 0)
|
||||
{
|
||||
std::this_thread::sleep_for(retryMs);
|
||||
pids = getDocKitPids();
|
||||
tries--;
|
||||
}
|
||||
|
||||
if (pids.contains(pid))
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Timed out waiting for kit process " << pid << " to stop. Active kit pids are: " << getPidList(pids);
|
||||
LOK_ASSERT_FAIL(oss.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
TST_LOG("Finished waiting for kit process " << pid << " to stop.");
|
||||
TST_LOG("Active kit pids are: " << getPidList(pids));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
#include <Protocol.hpp>
|
||||
#include <test.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <countcoolkits.hpp>
|
||||
#include <KitPidHelpers.hpp>
|
||||
|
||||
using namespace helpers;
|
||||
|
||||
|
@ -153,7 +153,7 @@ void HTTPCrashTest::testCrashKit()
|
|||
TST_LOG("Killing coolkit instances.");
|
||||
|
||||
killLoKitProcesses();
|
||||
countCoolKitProcesses(0, std::chrono::seconds(1));
|
||||
countCoolKitProcesses(0);//, std::chrono::seconds(1));
|
||||
|
||||
TST_LOG("Reading the error code from the socket.");
|
||||
//FIXME: implement in WebSocketSession.
|
||||
|
@ -188,7 +188,7 @@ void HTTPCrashTest::testRecoverAfterKitCrash()
|
|||
TST_LOG("Killing coolkit instances.");
|
||||
|
||||
killLoKitProcesses();
|
||||
countCoolKitProcesses(0, std::chrono::seconds(1));
|
||||
countCoolKitProcesses(0);//, std::chrono::seconds(1));
|
||||
|
||||
// We expect the client connection to close.
|
||||
TST_LOG("Reconnect after kill.");
|
||||
|
@ -270,7 +270,6 @@ static void killPids(const std::set<pid_t> &pids, const std::string& testname)
|
|||
void HTTPCrashTest::killLoKitProcesses()
|
||||
{
|
||||
killPids(getKitPids(), "killLoKitProcesses ");
|
||||
InitialCoolKitCount = 1; // non-intuitive but it will arrive soon.
|
||||
}
|
||||
|
||||
void HTTPCrashTest::killForkitProcess()
|
||||
|
|
|
@ -30,9 +30,9 @@
|
|||
#include <Common.hpp>
|
||||
#include <Protocol.hpp>
|
||||
|
||||
#include "lokassert.hpp"
|
||||
#include <countcoolkits.hpp>
|
||||
#include <lokassert.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <KitPidHelpers.hpp>
|
||||
|
||||
using namespace helpers;
|
||||
|
||||
|
@ -126,6 +126,7 @@ void HTTPWSTest::testExoticLang()
|
|||
|
||||
void HTTPWSTest::testSaveOnDisconnect()
|
||||
{
|
||||
|
||||
const std::string testname = "saveOnDisconnect- ";
|
||||
|
||||
const std::string text = helpers::genRandomString(40);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <Session.hpp>
|
||||
#include <Common.hpp>
|
||||
#include <common/FileUtil.hpp>
|
||||
#include <countcoolkits.hpp>
|
||||
#include <KitPidHelpers.hpp>
|
||||
|
||||
#include <Poco/Net/AcceptCertificateHandler.h>
|
||||
#include <Poco/Net/FilePartSource.h>
|
||||
|
@ -100,14 +100,14 @@ public:
|
|||
void setUp()
|
||||
{
|
||||
helpers::resetTestStartTime();
|
||||
testCountHowManyCoolkits();
|
||||
helpers::testCountHowManyCoolkits();
|
||||
helpers::resetTestStartTime();
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
helpers::resetTestStartTime();
|
||||
testNoExtraCoolKitsLeft();
|
||||
helpers::testNoExtraCoolKitsLeft();
|
||||
helpers::resetTestStartTime();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
#include <helpers.hpp>
|
||||
#include <Unit.hpp>
|
||||
#include <wsd/COOLWSD.hpp>
|
||||
#if ENABLE_SSL
|
||||
#include <Ssl.hpp>
|
||||
#include <SslSocket.hpp>
|
||||
|
@ -293,36 +292,4 @@ bool runClientTests(const char* cmd, bool standalone, bool verbose)
|
|||
return result.wasSuccessful();
|
||||
}
|
||||
|
||||
// Standalone tests don't really use WSD
|
||||
#ifndef STANDALONE_CPPUNIT
|
||||
|
||||
std::set<pid_t> getKitPids()
|
||||
{
|
||||
return COOLWSD::getKitPids();
|
||||
}
|
||||
std::set<pid_t> getSpareKitPids()
|
||||
{
|
||||
return COOLWSD::getSpareKitPids();
|
||||
}
|
||||
std::set<pid_t> getDocKitPids()
|
||||
{
|
||||
return COOLWSD::getDocKitPids();
|
||||
}
|
||||
|
||||
/// Get the PID of the forkit
|
||||
std::set<pid_t> getForKitPids()
|
||||
{
|
||||
std::set<pid_t> pids;
|
||||
if (COOLWSD::ForKitProcId >= 0)
|
||||
pids.emplace(COOLWSD::ForKitProcId);
|
||||
return pids;
|
||||
}
|
||||
|
||||
/// How many live coolkit processes do we have ?
|
||||
int getCoolKitProcessCount()
|
||||
{
|
||||
return getKitPids().size();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
|
|
@ -11,31 +11,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
#include <set>
|
||||
|
||||
/// Are we running inside WSD or by ourselves.
|
||||
bool isStandalone();
|
||||
|
||||
/// Run the set of client tests we have
|
||||
bool runClientTests(const char* cmd, bool standalone, bool verbose);
|
||||
|
||||
// ---- Abstraction for standalone vs. WSD ----
|
||||
|
||||
/// Get the list of all kit PIDs
|
||||
std::set<pid_t> getKitPids();
|
||||
/// Get the list of spare (unused) kit PIDs
|
||||
std::set<pid_t> getSpareKitPids();
|
||||
/// Get the list of doc (loaded) kit PIDs
|
||||
std::set<pid_t> getDocKitPids();
|
||||
|
||||
/// Get the PID of the forkit
|
||||
std::set<pid_t> getForKitPids();
|
||||
|
||||
/// Which port should we connect to get to WSD.
|
||||
int getClientPort();
|
||||
|
||||
/// How many live coolkit processes do we have ?
|
||||
int getCoolKitProcessCount();
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
|
Loading…
Reference in New Issue