summaryrefslogtreecommitdiffstats
path: root/tests/time.rs
blob: 3b17d7c81277d81262eb1699d56c8682a5316d26 (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
mod common;

use aur_build::db::{builds, BuildState};
use aur_build::time;
use common::Env;

// What remains is the test that needs a database: it pins a clock, takes a
// lease, and checks that expiry is measured against the pinned clock rather
// than the real one. The pure clock arithmetic moved into src/time.rs.

#[test]
fn a_lease_taken_under_a_pinned_clock_expires_against_that_clock() {
    let env = Env::new();
    env.exec("INSERT INTO pkgbase (name, aur_url, created_at) VALUES ('x', 'u', '2026-01-01T00:00:00Z')", &[]);
    let pb = env.query_i64("SELECT id FROM pkgbase WHERE name='x'", &[]).unwrap();
    builds::enqueue(&env.db, "b1", pb, None, "manual", None, "default", 0).unwrap();

    time::pin("2026-01-01T00:00:00Z");
    builds::claim(&env.db, "w1", "b1", 90).unwrap();
    assert_eq!(
        env.query_str("SELECT lease_expires_at FROM build WHERE id='b1'", &[]).as_deref(),
        Some("2026-01-01T00:01:30Z"),
        "the lease must be 90 seconds after the pinned now, not the real one"
    );
    assert_eq!(builds::reap_expired(&env.db).unwrap(), 0);
    time::pin("2026-01-01T00:01:31Z");
    assert_eq!(builds::reap_expired(&env.db).unwrap(), 1);
    assert_eq!(builds::get(&env.db, "b1").unwrap().unwrap().state, BuildState::Queued);
    time::unpin();
}