1
//! Re-running over an already-current fleet is safe, and never touches the admin.
2
#![cfg(feature = "db")]
3

            
4
use server::fleet::migrate_fleet;
5
use tests_integration::fleet_support::{
6
    accounted_for, admin_connect, admin_id, forget_tenant, is_fully_migrated, quarantine_of,
7
    register_tenant,
8
};
9

            
10
#[tokio::test]
11
1
async fn a_second_run_changes_nothing_and_spares_the_admin() -> anyhow::Result<()> {
12
1
    let admin = admin_connect().await;
13
1
    let (id, database_name) = register_tenant(&admin, "fleet-again", true).await;
14

            
15
1
    let first = migrate_fleet(admin_id()).await?;
16
1
    assert!(accounted_for(&first, id), "{first:?}");
17

            
18
1
    let second = migrate_fleet(admin_id()).await?;
19
1
    assert!(
20
1
        accounted_for(&second, id),
21
        "an already-current tenant is visited again and still passes: {second:?}"
22
    );
23
1
    assert!(is_fully_migrated(&database_name).await);
24
1
    assert_eq!(quarantine_of(&admin, id).await, None);
25

            
26
    // The admin row points at the GLOBAL database. Visiting it would migrate the
27
    // global schema through the tenant path, and quarantining it would take the
28
    // whole deployment offline.
29
1
    assert!(accounted_for(&second, admin_id()), "{second:?}");
30
1
    assert_eq!(quarantine_of(&admin, admin_id()).await, None);
31

            
32
1
    forget_tenant(&admin, id, &database_name).await;
33
2
    Ok(())
34
1
}