diff --git a/src/media_delivery/media_delivery.c b/src/media_delivery/media_delivery.c index 3a37e895..c3f152c5 100644 --- a/src/media_delivery/media_delivery.c +++ b/src/media_delivery/media_delivery.c @@ -1422,8 +1422,11 @@ int media_delivery_init(struct UTUN_INSTANCE* inst) { return -1; } + if (member_sync_add_props_cbk(inst, md_on_props_changed, md)) { + DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "%s: cannot subscribe to member roles", MD_ID); + etcp_router_unbind(inst, ETCP_RT_ID_MEDIA_DELIVERY); return -1; + } etcp_add_conn_status_cbk(inst, md_on_conn_status, md); - member_sync_add_props_cbk(inst, md_on_props_changed, md); md->initialized = 1; media_delivery_refresh_roles(inst); diff --git a/tests/test_media_delivery_chat.c b/tests/test_media_delivery_chat.c index 65ad8e26..0e384266 100644 --- a/tests/test_media_delivery_chat.c +++ b/tests/test_media_delivery_chat.c @@ -14,8 +14,8 @@ // 4. Второй клиент n2 скачивает медиа «по запросу» и собирает файл. // // Используется настоящий db_sync для доставки сообщения и настоящий media-движок -// для доставки блоков. chat_core НЕ используется (он — глобальный синглтон на процесс), -// поэтому связка «сообщение → auto-download» воспроизведена локальным insert-callback'ом. +// для доставки блоков. Связка «сообщение → auto-download» задаётся тестовым insert-callback'ом; +// per-instance chat_core хранит подписки на роли и общую БД каждого узла. #include "media_delivery.h" #include @@ -23,6 +23,7 @@ #include "media_download.h" #include "media_index.h" #include "member_sync.h" +#include "../chat/chat_core.h" #include "db_sync.h" #include "../routing_layer/topo_node_sqlite.h" #include "../utun_instance.h" @@ -479,7 +480,7 @@ static void setup_chat_group(void) { TEST("automatic SYNC s1<->s2 (via CHAT)"); { int a = 0, ok = 0; - while (a < 1000) { + while (a < 4000) { ok = db_count(g_inst[I_S1]->md.db, "super_sync", "group_id", g_group_id) > 0 && db_count(g_inst[I_S2]->md.db, "super_sync", "group_id", g_group_id) > 0; if (ok) break; @@ -571,8 +572,10 @@ int main(void) { test_etcp_set_peer(g_inst[i], peer, g_inst[j], "s1"); } utun_instance_init(g_inst[i]); - media_delivery_init(g_inst[i]); - member_sync_init(g_inst[i]); + char chat_db[512]; snprintf(chat_db, sizeof(chat_db), "%s/chats.db", g_db_dir[i]); + if (chat_core_init(g_inst[i], chat_db) || member_sync_init(g_inst[i]) || media_delivery_init(g_inst[i])) { + FAIL("chat/media initialization n%d", i); goto done; + } } mon(NULL); diff --git a/tests/test_media_delivery_full.c b/tests/test_media_delivery_full.c index 4d3199c6..0c821aef 100644 --- a/tests/test_media_delivery_full.c +++ b/tests/test_media_delivery_full.c @@ -14,6 +14,7 @@ #include "media_download.h" #include "media_index.h" #include "member_sync.h" +#include "../chat/chat_core.h" #include "../routing_layer/topo_node_sqlite.h" #include "../utun_instance.h" #include "../transport_layer/etcp.h" @@ -447,6 +448,8 @@ int main(void) { test_etcp_set_peer(g_inst[i], peer, g_inst[i - 1], "s1"); } utun_instance_init(g_inst[i]); + char chat_db[512]; snprintf(chat_db, sizeof(chat_db), "%s/chats.db", g_db_dir[i]); + if (chat_core_init(g_inst[i], chat_db)) { FAIL("chat_core_init n%d", i); goto done; } if (member_sync_init(g_inst[i]) < 0) { FAIL("member_sync_init n%d", i); goto done; } assert(!media_index_init(g_inst[i]->topo_sqlite_db)); assert(!media_delivery_init(g_inst[i]));