Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/Progmasoft/Runner/Planner.hpp
blob: f688fe5069f8a52d73c3507c8057bbef87c4d7a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2026 Progmasoft.
// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-2.0
#pragma once

#include "Catalog.hpp"
#include "Expected.hpp"
#include "Git.hpp"
#include "History.hpp"
#include "Options.hpp"

#include <chrono>
#include <cstdint>
#include <map>
#include <optional>
#include <string>
#include <vector>

namespace Progmasoft::Catch3::Runner
{
    /// One test the run will start, with everything decided in advance.
    struct PlannedTest final
    {
        const TestEntry *entry = nullptr;
        std::string selectionReason;
        double failureProbability = 0.0;
        std::int64_t predictedMicroseconds = 0;
        /// Zero: no limit.
        std::chrono::milliseconds timeout{0};
        bool timeoutLearned = false;
        unsigned retryLimit = 0;
        bool quarantined = false;
        std::string quarantineReason;
        /// The history shows the test passing and failing with the same
        /// inputs.
        bool flakyHistory = false;
        /// Positions in `Plan::tests` of the tests this one waits for.
        std::vector<std::size_t> dependencies;
        /// What the result depends on; equal for an unchanged test.
        std::string fingerprint;
        /// For --replay: the tests (catalog indices) to run before it in the
        /// same fresh process, and the seed it failed with.
        std::optional<std::vector<std::size_t>> replaySequence;
        std::optional<std::uint32_t> replaySeed;
    };

    /// What a run will do, decided before the first test starts.
    struct Plan final
    {
        /// In the order the scheduler should prefer.
        std::vector<PlannedTest> tests;
        /// Tests whose earlier result stands: up to date or out of the
        /// selection but needed by nothing.
        std::vector<TestResult> kept;
        std::vector<std::string> unmatchedSpecs;
        std::vector<std::string> notes;
        /// Tests that matched the specs, before selection and sharding.
        std::size_t candidates = 0;
        std::map<std::string, std::string> fingerprints;
    };

    /// What the planner reads besides the options.
    struct PlanInputs final
    {
        const Catalog *catalog = nullptr;
        /// The tests the specs matched, in registration order.
        std::vector<std::size_t> matched;
        std::vector<std::string> unmatchedSpecs;
        const History *history = nullptr;
        /// Present when Git answered.
        const Changes *changes = nullptr;
        /// A digest of the test binary.
        std::string binaryFingerprint;
    };

    [[nodiscard]] Expected<Plan>
    MakePlan(const Options &options, const PlanInputs &inputs);

    /// The shard of a group of tests that must stay together, by a hash of
    /// its first key. Every machine computes the same answer.
    [[nodiscard]] unsigned
    StableShard(const std::string &key, unsigned count) noexcept;
} // namespace Progmasoft::Catch3::Runner