fix: preserve signed terminal nonstarts across repeated and restarted sync
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -758,7 +758,13 @@ fn attempts(db: &Connection, ledger: &Connection, binding: &Binding) -> Result<V
|
||||
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?, r.get(3)?)),
|
||||
)
|
||||
.optional()?;
|
||||
let mut consumption = if grant_id.is_empty() && state == "accepted" {
|
||||
// A signed definitive nonstart can make an accepted no-grant row
|
||||
// terminal without a JobResult. Preserve that fact on the next Sync;
|
||||
// requesting/running/unknown still cannot claim non-consumption. An
|
||||
// actual durable consumption row below always overrides this label.
|
||||
let mut consumption = if grant_id.is_empty()
|
||||
&& matches!(state.as_str(), "accepted" | "expired" | "cancelled")
|
||||
{
|
||||
"unconsumed"
|
||||
} else {
|
||||
"uncertain"
|
||||
|
||||
@@ -456,6 +456,123 @@ fn definite_nonstart_result_is_unconsumed_not_ambiguous() {
|
||||
assert!(c.can_start(&f.channel, false, &f.clock));
|
||||
}
|
||||
#[test]
|
||||
fn signed_terminal_nonstart_stays_unconsumed_across_sync_and_pending_denial() {
|
||||
for terminal in ["expired", "cancelled"] {
|
||||
let mut f = Fixture::new();
|
||||
let (offer, _, _) = f.add("accepted", false, None, script());
|
||||
let mut client = f.client();
|
||||
let first = f.prepare(&mut client);
|
||||
assert_eq!(first.request.attempts[0].consumption, "unconsumed");
|
||||
let mut decision = f.decision(&first, true);
|
||||
decision.attempts[0].outcome_state = terminal.into();
|
||||
decision.attempts[0].reason = "DEFINITIVE_NONSTART".into();
|
||||
f.apply(&mut client, &decision).unwrap();
|
||||
assert!(client.can_start(&f.channel, false, &f.clock));
|
||||
|
||||
let second = f.prepare(&mut client);
|
||||
let local = &second.request.attempts[0];
|
||||
assert_eq!(local.state, terminal);
|
||||
assert_eq!(local.consumption, "unconsumed");
|
||||
assert!(local.grant_id.is_empty() && local.outcome_bytes.is_empty());
|
||||
let mut repeated = f.decision(&second, true);
|
||||
repeated.attempts[0].reason = "DEFINITIVE_NONSTART".into();
|
||||
f.apply(&mut client, &repeated).unwrap();
|
||||
assert!(client.can_start(&f.channel, false, &f.clock));
|
||||
|
||||
// Reproduce the old server's rejected terminal->unknown response.
|
||||
// Keep its pending request and the last applied signed anchor, then
|
||||
// recover through a fresh channel/request with the ordinary protocol.
|
||||
let pending = f.prepare(&mut client);
|
||||
let mut denied = f.decision(&pending, false);
|
||||
denied.attempts[0].outcome_state = "unknown".into();
|
||||
denied.attempts[0].reason = "GRANT_OR_EFFECT_UNRESOLVED".into();
|
||||
assert!(f.apply(&mut client, &denied).is_err());
|
||||
assert!(!client.can_start(&f.channel, false, &f.clock));
|
||||
client = f.client();
|
||||
f.channel.connection_generation += 1;
|
||||
let fresh = f.prepare(&mut client);
|
||||
assert_eq!(
|
||||
fresh.request.previous_request_id,
|
||||
pending.request.request_id
|
||||
);
|
||||
assert_eq!(
|
||||
fresh.request.previous_decision_id,
|
||||
repeated.decision_id.to_string()
|
||||
);
|
||||
assert_eq!(fresh.request.attempts[0].consumption, "unconsumed");
|
||||
let mut recovered = f.decision(&fresh, true);
|
||||
recovered.attempts[0].reason = "DEFINITIVE_NONSTART".into();
|
||||
f.apply(&mut client, &recovered).unwrap();
|
||||
assert!(client.can_start(&f.channel, false, &f.clock));
|
||||
let stored: (String, String, String) =
|
||||
f.db.query_row("SELECT job,attempt,state FROM job_attempts", [], |r| {
|
||||
Ok((r.get(0)?, r.get(1)?, r.get(2)?))
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(stored, (offer.job_id, offer.attempt_id, terminal.into()));
|
||||
assert_eq!(
|
||||
f.ledger
|
||||
.query_row("SELECT count(*) FROM consumed", [], |r| r.get::<_, i64>(0))
|
||||
.unwrap(),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
f.db.query_row("SELECT count(*) FROM reconcile_outcomes", [], |r| r
|
||||
.get::<_, i64>(0))
|
||||
.unwrap(),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn terminal_labels_never_override_grant_consumption_or_unclear_attempts() {
|
||||
for state in ["requesting", "running", "unknown"] {
|
||||
let mut f = Fixture::new();
|
||||
f.add(state, false, None, script());
|
||||
let mut client = f.client();
|
||||
let prepared = f.prepare(&mut client);
|
||||
assert_eq!(prepared.request.attempts[0].consumption, "uncertain");
|
||||
let decision = f.decision(&prepared, true);
|
||||
f.apply(&mut client, &decision).unwrap();
|
||||
assert!(!client.can_start(&f.channel, false, &f.clock));
|
||||
}
|
||||
for terminal in ["expired", "cancelled"] {
|
||||
for consumed in [false, true] {
|
||||
let mut f = Fixture::new();
|
||||
f.add(terminal, consumed, None, script());
|
||||
// A surviving grant ID also forbids the nonstart shortcut when
|
||||
// no consumption row exists. A real row always remains consumed.
|
||||
if !consumed {
|
||||
f.db.execute(
|
||||
"UPDATE job_attempts SET grant_id=?1",
|
||||
[Uuid::new_v4().to_string()],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
let mut client = f.client();
|
||||
let prepared = f.prepare(&mut client);
|
||||
assert_eq!(
|
||||
prepared.request.attempts[0].consumption,
|
||||
if consumed { "consumed" } else { "uncertain" }
|
||||
);
|
||||
let mut decision = f.decision(&prepared, true);
|
||||
decision.attempts[0].unlock = false;
|
||||
assert!(f.apply(&mut client, &decision).is_err());
|
||||
assert!(!client.can_start(&f.channel, false, &f.clock));
|
||||
assert_eq!(
|
||||
f.ledger
|
||||
.query_row(
|
||||
"SELECT count(*) FROM consumed WHERE result IS NULL",
|
||||
[],
|
||||
|r| r.get::<_, i64>(0)
|
||||
)
|
||||
.unwrap(),
|
||||
i64::from(consumed)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn negative_server_revision_never_rolls_back_local_unknown_revision() {
|
||||
let mut f = Fixture::new();
|
||||
f.add("running", true, None, script());
|
||||
|
||||
Reference in New Issue
Block a user