Expire DM test custody only after confirmed storage

This commit is contained in:
evgeny committed 2026-10-26 18:42:45 +01:00
1 parent 669194ee01
commit cca1f2f52f
1 file changed
+32 -1
+32 -1
View File
@@ -46,6 +46,7 @@ struct media_test {
size_t body_len;
unsigned phase, ticks, heartbeats, work_ticks;
uint64_t recovery_start;
int expiry_armed;
int failed;
void* timer;
};
@@ -252,6 +253,29 @@ static int snapshot(struct media_test* t, unsigned seq) {
return 0;
}
/* После настоящего STORED синхронно приблизить срок S/M; скорость worker не определяет исход TTL-теста. */
static int expire_fixture(struct media_test* t) {
uint64_t deadline = ntp_time_get_seconds(t->nodes[S]);
const char* sql[] = { "UPDATE dm_media_jobs SET expires=?,retry_at=0 WHERE id=?",
"UPDATE dm_custody SET expires=?,retry_at=0 WHERE id=?" };
for (int i = 0; i < 2; i++) {
sqlite3* db = t->nodes[S + i]->topo_sqlite_db;
sqlite3_stmt* st = NULL;
int rc = sqlite3_prepare_v2(db, sql[i], -1, &st, NULL);
if (rc == SQLITE_OK) rc = sqlite3_bind_int64(st, 1, (sqlite3_int64)deadline);
if (rc == SQLITE_OK) rc = sqlite3_bind_blob(st, 2, t->id, 16, SQLITE_STATIC);
if (rc == SQLITE_OK) rc = sqlite3_step(st);
int final = sqlite3_finalize(st);
if (rc != SQLITE_DONE || final != SQLITE_OK || sqlite3_changes(db) != 1) {
DEBUG_ERROR(DEBUG_CATEGORY_DM, "DM expiry test: deadline setup failed node=%d rc=%d finalize=%d", S + i, rc, final);
return -1;
}
}
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "DM expiry test: STORED confirmed before matching S/M deadline=%llu",
(unsigned long long)deadline);
return 0;
}
/* Полученный файл сверяется побайтно; размер или ready-флаг недостаточны. */
static int file_correct(struct media_test* t) {
sqlite3_stmt* st = NULL;
@@ -550,7 +574,7 @@ static void tick(void* arg) {
case 6:
if (live(a, t->ids[B]) && value(a, "SELECT count(*) FROM dm_files WHERE receipt IS NOT NULL") == 2) {
utun_instance_destroy(b); t->nodes[B] = NULL;
if (chat_setting_set(m, "dm_media_ttl_sec", "1")) { failure(t, "TTL setting"); return; }
if (chat_setting_set(m, "dm_media_ttl_sec", "3600")) { failure(t, "TTL setting"); return; }
#ifdef DM_QUOTA_FAULT_INJECTION
release_db = s->topo_sqlite_db; expiry_storage_db = m->topo_sqlite_db; expiry_block = 1;
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "DM expiry test: lost EXPIRED and SQL failures enabled until M retires custody");
@@ -565,6 +589,13 @@ static void tick(void* arg) {
}
break;
case 8:
if (!t->expiry_armed) {
if (value(s, "SELECT count(*) FROM dm_media_jobs WHERE seq=3 AND stored=1") != 1 ||
value(m, "SELECT count(*) FROM dm_custody WHERE ready=1") != 1) break;
if (snapshot(t, 3) || expire_fixture(t)) { failure(t, "confirmed custody expiry setup"); return; }
t->expiry_armed = 1;
break;
}
if (value(m, "SELECT count(*) FROM dm_custody_done WHERE receipt IS NULL") == 1) {
#ifdef DM_QUOTA_FAULT_INJECTION
if (!expiry_restarted) {