enqueueResult function
Resolves the result's pending attachments and buffers it for upload.
With an upload pool armed the work runs there, so the test never waits on a blob; endReporting drains the pool before the final flush. A result that is never reported hands its blob bodies back instead of holding the bytes.
Implementation
void enqueueResult(ReporterState? state, PendingResult? item) {
if (item == null || item.ctx == null) return;
item.payload ??= snapshotPayload(item.ctx);
final session = state?._session;
final buffer = state?._buffer;
if ((item.ctx?.testCaseId ?? 0) <= 0) {
// Visible only at debug (PRODUCT / adapters Callout).
final label = (item.ctx?.autotestName ?? '').trim();
logDebug(
'Tracera: skip report — no testCaseId (${label.isEmpty ? 'unbound' : label})',
);
discardPendingBlobs(item.payload);
return;
}
if (state == null ||
state.softDisabled ||
session == null ||
buffer == null) {
discardPendingBlobs(item.payload);
return;
}
Future<void> report() async {
if (!session.reportingEnabled) {
discardPendingBlobs(item.payload);
return;
}
if (!await resolveResultAttachments(session, item.payload!)) return;
buffer.enqueue(item);
}
final pool = state._uploadPool;
if (pool == null) {
// No pool: the caller owns the wait. Fire it and let the final flush
// pick the result up — errors inside report() are handled by the session.
unawaited(report());
return;
}
pool.enqueue(report);
}