|
|
@@ -75,6 +75,10 @@ struct CompletedJob {
|
|
|
bool ok = false;
|
|
|
std::string error;
|
|
|
uint32_t retryAfterSec = 0;
|
|
|
+ /// Recorded so a test can assert the KIND reached the queue. Without this
|
|
|
+ /// the fake would swallow it and every test would pass whether or not the
|
|
|
+ /// classification was passed through at all.
|
|
|
+ std::string failureKind;
|
|
|
};
|
|
|
|
|
|
class FakeQueue : public JobQueuePort {
|
|
|
@@ -90,9 +94,9 @@ public:
|
|
|
return job;
|
|
|
}
|
|
|
bool complete(const JobView& job, bool ok, const std::string& error,
|
|
|
- uint32_t retryAfterSec) override {
|
|
|
+ uint32_t retryAfterSec, const std::string& failureKind) override {
|
|
|
std::lock_guard<std::mutex> lock(m);
|
|
|
- completed.push_back({job.jobId, ok, error, retryAfterSec});
|
|
|
+ completed.push_back({job.jobId, ok, error, retryAfterSec, failureKind});
|
|
|
return !failComplete;
|
|
|
}
|
|
|
uint32_t reclaimStale(uint32_t, uint32_t) override {
|
|
|
@@ -673,3 +677,89 @@ TEST(Threads, TheStaleSweepIsOffUnlessAnIntervalIsSet) {
|
|
|
}
|
|
|
EXPECT_GT(queue.sweeps, 0);
|
|
|
}
|
|
|
+
|
|
|
+// ------------------------------------------------- the failure KIND survives
|
|
|
+
|
|
|
+// The names are a CONTRACT, so they are pinned by value rather than by
|
|
|
+// round-tripping the enum through itself. A test asserting
|
|
|
+// `jobFailureName(FunctionFault) == jobFailureName(FunctionFault)` would pass
|
|
|
+// after someone respelled it, which is precisely the change that must break.
|
|
|
+TEST(FailureKind, TheWireNamesArePinnedByValue) {
|
|
|
+ EXPECT_STREQ("", jobFailureName(JobFailure::None));
|
|
|
+ EXPECT_STREQ("function_fault", jobFailureName(JobFailure::FunctionFault));
|
|
|
+ EXPECT_STREQ("runner_fault", jobFailureName(JobFailure::RunnerFault));
|
|
|
+ EXPECT_STREQ("transient_lookup", jobFailureName(JobFailure::TransientLookup));
|
|
|
+ EXPECT_STREQ("malformed", jobFailureName(JobFailure::Malformed));
|
|
|
+}
|
|
|
+
|
|
|
+// "it failed" is not the question anyone asks. `runner_fault` is ours and
|
|
|
+// `function_fault` is the tenant's, and routing both to one alarm is how an
|
|
|
+// on-call rota learns to ignore it.
|
|
|
+TEST(FailureKind, OnlyAFunctionFaultBlamesTheFunction) {
|
|
|
+ EXPECT_TRUE(isFunctionAtFault(JobFailure::FunctionFault));
|
|
|
+ EXPECT_FALSE(isFunctionAtFault(JobFailure::RunnerFault));
|
|
|
+ EXPECT_FALSE(isFunctionAtFault(JobFailure::TransientLookup));
|
|
|
+ EXPECT_FALSE(isFunctionAtFault(JobFailure::Malformed));
|
|
|
+ EXPECT_FALSE(isFunctionAtFault(JobFailure::None));
|
|
|
+}
|
|
|
+
|
|
|
+// It reaches the QUEUE, which is what #70 was about: the worker always
|
|
|
+// classified the failure and then discarded it, storing only a state and a
|
|
|
+// free-text message.
|
|
|
+TEST(FailureKind, AThrowingFunctionReachesTheQueueAsAFunctionFault) {
|
|
|
+ FakeSource source;
|
|
|
+ source.put("p", "f",
|
|
|
+ "export const on = { id: 'f', type: 'cron', schedule: '* * * * *' };\n"
|
|
|
+ "export default async () => { throw new Error('boom'); };\n");
|
|
|
+ RunService service(source, serviceOptions());
|
|
|
+ FakeQueue queue;
|
|
|
+ FakeLog log;
|
|
|
+ queue.pending.push_back(job("j1", "f"));
|
|
|
+ JobWorker worker(service, queue, log, workerOptions());
|
|
|
+
|
|
|
+ EXPECT_TRUE(worker.runOnce());
|
|
|
+ ASSERT_EQ(queue.completed.size(), 1u);
|
|
|
+ EXPECT_FALSE(queue.completed[0].ok);
|
|
|
+ EXPECT_EQ(queue.completed[0].failureKind, "function_fault");
|
|
|
+ // And onto the run log, which is what an operator reads - the queue row is
|
|
|
+ // deleted when the job is reaped, so storing it only there would keep the
|
|
|
+ // classification exactly as long as nobody needed it.
|
|
|
+ ASSERT_EQ(log.entries.size(), 1u);
|
|
|
+ EXPECT_EQ(log.entries[0].second.failureKind, "function_fault");
|
|
|
+}
|
|
|
+
|
|
|
+// A successful run must carry NO kind. Without this the whole family could be
|
|
|
+// hardcoded to "function_fault" and every test above would still pass.
|
|
|
+TEST(FailureKind, ASuccessfulRunCarriesNoKindAtAll) {
|
|
|
+ FakeSource source;
|
|
|
+ source.put("p", "f",
|
|
|
+ "export const on = { id: 'f', type: 'cron', schedule: '* * * * *' };\n"
|
|
|
+ "export default async () => ({ body: 'ok' });\n");
|
|
|
+ RunService service(source, serviceOptions());
|
|
|
+ FakeQueue queue;
|
|
|
+ FakeLog log;
|
|
|
+ queue.pending.push_back(job("j1", "f"));
|
|
|
+ JobWorker worker(service, queue, log, workerOptions());
|
|
|
+
|
|
|
+ EXPECT_TRUE(worker.runOnce());
|
|
|
+ ASSERT_EQ(queue.completed.size(), 1u);
|
|
|
+ EXPECT_TRUE(queue.completed[0].ok);
|
|
|
+ EXPECT_EQ(queue.completed[0].failureKind, "");
|
|
|
+ ASSERT_EQ(log.entries.size(), 1u);
|
|
|
+ EXPECT_EQ(log.entries[0].second.failureKind, "");
|
|
|
+}
|
|
|
+
|
|
|
+// A corrupt row is OUR bug, not the tenant's, and it must not be reported as
|
|
|
+// one. This is the case that reaches complete() without the engine running.
|
|
|
+TEST(FailureKind, ARowWithNoFunctionIdIsMalformedNotAFunctionFault) {
|
|
|
+ FakeSource source;
|
|
|
+ RunService service(source, serviceOptions());
|
|
|
+ FakeQueue queue;
|
|
|
+ FakeLog log;
|
|
|
+ queue.pending.push_back(job("j1", ""));
|
|
|
+ JobWorker worker(service, queue, log, workerOptions());
|
|
|
+
|
|
|
+ EXPECT_TRUE(worker.runOnce());
|
|
|
+ ASSERT_EQ(queue.completed.size(), 1u);
|
|
|
+ EXPECT_EQ(queue.completed[0].failureKind, "malformed");
|
|
|
+}
|