test(media): verify exact announcement identities after SQL recovery

This commit is contained in:
evgeny committed 2026-10-24 17:26:11 +02:00
1 parent eea2b22c4e
commit 6e3be1aaf3
1 file changed
+10 -3
+10 -3
View File
@@ -14,7 +14,8 @@ int __real_sqlite3_finalize(sqlite3_stmt*);
/* Ошибки внедряются только в внешний обход; вложенные SQL анонса остаются настоящими. */
int __wrap_sqlite3_prepare_v2(sqlite3* db, const char* command, int size, sqlite3_stmt** st, const char** tail) {
int target = sql_fault && !strncmp(command, "SELECT id,media_id,block_id,chunk,chat_id FROM media_files", 54);
static const char prefix[] = "SELECT id,media_id,block_id,chunk,chat_id FROM media_files";
int target = sql_fault && !strncmp(command, prefix, sizeof(prefix) - 1);
if (target && sql_fault == SQL_PREPARE) { *st = NULL; fault_injected++; return SQLITE_NOMEM; }
int rc = __real_sqlite3_prepare_v2(db, command, size, st, tail);
if (target && rc == SQLITE_OK) fault_statement = *st;
@@ -141,7 +142,7 @@ static void test_announcements(void) {
insert_announcement(a->md.db, "x'01'", "x'ff'", "1", NULL);
insert_announcement(a->md.db, NULL, ANN_BLOCK_SECOND, "4294967295", "'18446744073709551615'");
reset(); capture_blocks = 1;
media_delivery_announce_local_blocks(a); REQUIRE(packet_count == 2);
media_delivery_announce_local_blocks(a); REQUIRE(packet_count == 2 && packets[0].group != packets[1].group);
for (int i = 0; i < packet_count; i++) {
const struct media_pkt_have_block* hb = (const struct media_pkt_have_block*)packets[i].data;
check_announcement(&packets[i], hb->chunk ? UINT64_MAX : GROUP, hb->chunk ? UINT32_MAX : 0, hb->chunk ? 0x31 : 0x30);
@@ -170,7 +171,13 @@ static void test_announcements(void) {
if (fault != SQL_PREPARE) REQUIRE(strstr(log, "local block scan incomplete"));
sql_fault = SQL_NONE; reset(); capture_blocks = 1;
media_delivery_announce_local_blocks(a); REQUIRE(packet_count == 2 && sqlite3_next_stmt(a->md.db, NULL) == NULL);
check_announcement(&packets[0], GROUP, ((const struct media_pkt_have_block*)packets[0].data)->chunk, packets[0].data[48]);
unsigned seen = 0;
for (int i = 0; i < packet_count; i++) {
uint32_t chunk = ((const struct media_pkt_have_block*)packets[i].data)->chunk;
REQUIRE(chunk < 2 && !(seen & (1u << chunk))); seen |= 1u << chunk;
check_announcement(&packets[i], GROUP, chunk, chunk ? 0x31 : 0x30);
}
REQUIRE(seen == 3);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "announcement SQL fault=%d injected=1 packets_before_error=%d recovery=2 PASS", fault, expected);
}
#endif