Fix adding last package of current batch already to staging repository

This commit is contained in:
Martchus 2022-09-20 21:58:33 +02:00
parent 833550197f
commit a205ffae38
7 changed files with 41 additions and 16 deletions

View File

@ -527,6 +527,7 @@ private:
bool m_skipBatchesAfterFailure;
bool m_hasFailuresInPreviousBatches;
std::atomic_bool m_enableStagingInNextBatch;
std::atomic_bool m_enableStagingInThisBatch;
std::atomic_bool m_stagingEnabled;
};

View File

@ -81,6 +81,7 @@ BatchProcessingSession::BatchProcessingSession(const std::unordered_set<string_v
, m_skipBatchesAfterFailure(skipBatchesAfterFailure)
, m_hasFailuresInPreviousBatches(false)
, m_enableStagingInNextBatch(false)
, m_enableStagingInThisBatch(false)
, m_stagingEnabled(false)
{
}
@ -98,6 +99,9 @@ bool BatchProcessingSession::isValid() const
/*!
* \brief Returns whether staging is now active after a previous call to enableStagingInNextBatch().
* \remarks
* This function's return value relates to the package returned by getCurrentPackageNameIfValidAndRelevantAndSelectNext()
* despite that function selecting the next package.
*/
bool BatchProcessingSession::isStagingEnabled() const
{
@ -128,6 +132,7 @@ void BatchProcessingSession::selectNextPackage()
{
if (++m_packageIterator != m_packageEnd) {
m_firstPackageInBatch = false;
m_stagingEnabled = m_stagingEnabled || m_enableStagingInThisBatch;
return; // select the next package within the current batch
}
if ((m_hasFailuresInPreviousBatches = !allResponses().empty()) && m_skipBatchesAfterFailure) {
@ -140,7 +145,7 @@ void BatchProcessingSession::selectNextPackage()
m_packageIterator = m_batchIterator->begin();
m_packageEnd = m_batchIterator->end();
m_firstPackageInBatch = true;
m_stagingEnabled = m_stagingEnabled || m_enableStagingInNextBatch;
m_enableStagingInThisBatch.store(m_enableStagingInNextBatch);
}
/*!

View File

@ -0,0 +1,3 @@
pkgname = bar
pkgver = 2-1
pkgdesc = another fake package for testing

View File

@ -0,0 +1,3 @@
pkgname = foo
pkgver = 1-1
pkgdesc = fake package for testing

View File

@ -429,13 +429,19 @@ static void ensureEmptyDir(const std::filesystem::path &path)
static void createPackageDirs(bool empty = true)
{
constexpr auto buildDir = "building/build-data/conduct-build-test/"sv;
for (const auto pkg : { "foo"sv, "bar"sv, "baz"sv }) {
ensureEmptyDir(argsToString(buildDir, pkg, "/src"sv));
ensureEmptyDir(argsToString(buildDir, pkg, "/pkg"sv));
for (const auto pkg : { "foo-1-1"sv, "bar-2-1"sv, "baz-3-1"sv }) {
const auto pkgName = pkg.substr(0, 3);
ensureEmptyDir(argsToString(buildDir, pkgName, "/src"sv));
ensureEmptyDir(argsToString(buildDir, pkgName, "/pkg"sv));
if (!empty) {
writeFile(argsToString(buildDir, pkg, "/src/PKGBUILD"sv), pkg);
writeFile(argsToString(buildDir, pkg, "/src/"sv, pkg, "-1-1.src.tar.gz"sv), pkg);
writeFile(argsToString(buildDir, pkg, "/src/"sv, pkg, "-1-1-x86_64.pkg.tar.zst"sv), pkg);
const auto relativeFakePackagePath = argsToString(buildDir, pkgName, "/src/"sv, pkg, "-x86_64.pkg.tar.zst"sv);
try {
std::filesystem::copy_file(testFilePath(relativeFakePackagePath), relativeFakePackagePath);
} catch (const std::runtime_error &) {
writeFile(relativeFakePackagePath, pkg);
}
writeFile(argsToString(buildDir, pkgName, "/src/PKGBUILD"sv), pkg);
writeFile(argsToString(buildDir, pkgName, "/src/"sv, pkg, ".src.tar.gz"sv), pkg);
}
}
}
@ -644,15 +650,14 @@ void BuildActionsTests::testConductingBuild()
createPackageDirs(false);
// conduct build with staging and multiple batches
// FIXME: verify behavior of packages other than boost
{
writeFile(progressFile.native(), progressData); // reset "build-progress.json" so the packages are re-considered
m_buildAction->packageNames.clear(); // don't build only "boost"
runBuildAction("conduct build with staging");
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"staging needed: failure (as most build results are just dummies here)", BuildActionResult::Failure, m_buildAction->result);
"staging needed: failure as build result of baz is no valid archive", BuildActionResult::Failure, m_buildAction->result);
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"staging needed: no result data present", "failed to build packages: foo, bar, baz"s, std::get<std::string>(m_buildAction->resultData));
"staging needed: failed packages listed", "failed to build packages: baz"s, std::get<std::string>(m_buildAction->resultData));
internalData = internalBuildAction<ConductBuild>();
const auto &rebuildList = internalData->m_buildProgress.rebuildList;
const auto rebuildInfoForMisc = rebuildList.find("misc");
@ -671,16 +676,24 @@ void BuildActionsTests::testConductingBuild()
readFile("building/build-data/conduct-build-test/boost/pkg/repo-add.log"));
// check whether package have been added to staging repo
CPPUNIT_ASSERT_MESSAGE(
"staging needed: package added to repo (0)", std::filesystem::is_regular_file("repos/boost-staging/os/src/boost-1.73.0-1.src.tar.gz"));
CPPUNIT_ASSERT_MESSAGE("staging needed: package added to repo (1)",
CPPUNIT_ASSERT_MESSAGE("staging needed: boost package added to staging repo (0)",
std::filesystem::is_regular_file("repos/boost-staging/os/src/boost-1.73.0-1.src.tar.gz"));
CPPUNIT_ASSERT_MESSAGE("staging needed: boost package added to staging repo (1)",
std::filesystem::is_regular_file("repos/boost-staging/os/x86_64/boost-1.73.0-1-x86_64.pkg.tar.zst"));
CPPUNIT_ASSERT_MESSAGE("staging needed: package added to repo (2)",
CPPUNIT_ASSERT_MESSAGE("staging needed: boost package added to staging repo (2)",
std::filesystem::is_regular_file("repos/boost-staging/os/x86_64/boost-libs-1.73.0-1-x86_64.pkg.tar.zst"));
CPPUNIT_ASSERT_MESSAGE("staging needed: signature added to repo (0)",
CPPUNIT_ASSERT_MESSAGE("staging needed: boost signature added to staging repo (0)",
std::filesystem::is_regular_file("repos/boost-staging/os/x86_64/boost-1.73.0-1-x86_64.pkg.tar.zst.sig"));
CPPUNIT_ASSERT_MESSAGE("staging needed: signature added to repo (1)",
CPPUNIT_ASSERT_MESSAGE("staging needed: boost signature added to staging repo (1)",
std::filesystem::is_regular_file("repos/boost-staging/os/x86_64/boost-libs-1.73.0-1-x86_64.pkg.tar.zst.sig"));
CPPUNIT_ASSERT_MESSAGE("staging needed: foo package from first batch still added to normal repo (0)",
std::filesystem::is_regular_file("repos/boost/os/src/foo-1-1.src.tar.gz"));
CPPUNIT_ASSERT_MESSAGE("staging needed: foo package from first batch still added to normal repo (1)",
std::filesystem::is_regular_file("repos/boost/os/x86_64/foo-1-1-x86_64.pkg.tar.zst"));
CPPUNIT_ASSERT_MESSAGE("staging needed: bar package from next batch added to staging repo as well (0)",
std::filesystem::is_regular_file("repos/boost-staging/os/src/bar-2-1.src.tar.gz"));
CPPUNIT_ASSERT_MESSAGE("staging needed: bar package from next batch added to staging repo as well (1)",
std::filesystem::is_regular_file("repos/boost-staging/os/x86_64/bar-2-1-x86_64.pkg.tar.zst"));
}
// define expected errors for subsequent tests