Use distinct regression helper name and reserved uasync post API
This commit is contained in:
1 parent
99ebee37e7
commit
289b592598
1 file changed
+11
-10
@@ -158,7 +158,7 @@ static void source_preserved(struct fixture* f) {
|
||||
assert(fgetc(file) == EOF && !fclose(file));
|
||||
}
|
||||
|
||||
static int send(struct fixture* f) {
|
||||
static int send_attachment(struct fixture* f) {
|
||||
struct attachment_info info = {.kind = ATTACHMENT_FILE, .name = "source.bin"}; uint8_t reply[32] = {0};
|
||||
return chat_attachment_send(f->inst, f->channel, f->source, &info, "application/octet-stream", reply, 71);
|
||||
}
|
||||
@@ -174,7 +174,7 @@ static void unchanged(struct fixture* f) {
|
||||
}
|
||||
|
||||
static void publish(struct fixture* f) {
|
||||
assert(!send(f) && f->submissions == 1); f->rows++;
|
||||
assert(!send_attachment(f) && f->submissions == 1); f->rows++;
|
||||
for (unsigned poll = 0; poll < 2000 && !f->events; poll++) uasync_poll(f->ua, 10);
|
||||
assert(f->events == 1 && f->success == 1 && rows(f) == f->rows && ma_file_size(f->source) < 0);
|
||||
committed(f, 1); uasync_poll(f->ua, 0); assert(f->events == 1);
|
||||
@@ -211,7 +211,7 @@ static void test_sql_faults(void) {
|
||||
struct fixture f; setup(&f);
|
||||
for (enum fault stage = BEGIN; stage < FAULT_COUNT; stage++) {
|
||||
source(&f); unsigned before = 0, after = 0; assert(!ma_dir_walk(f.directory, count_files, &before));
|
||||
fault = stage; assert(send(&f) == -1); unchanged(&f);
|
||||
fault = stage; assert(send_attachment(&f) == -1); unchanged(&f);
|
||||
assert(!ma_dir_walk(f.directory, count_files, &after) && before == after);
|
||||
source(&f); publish(&f);
|
||||
}
|
||||
@@ -224,18 +224,18 @@ static int veto_commit(void* arg) { (*(unsigned*)arg)++; return 1; }
|
||||
static void test_sql_controls(void) {
|
||||
struct fixture f; setup(&f); unsigned vetoes = 0;
|
||||
source(&f); sqlite3_commit_hook(f.inst->topo_sqlite_db, veto_commit, &vetoes);
|
||||
assert(send(&f) == -1 && vetoes == 1); sqlite3_commit_hook(f.inst->topo_sqlite_db, NULL, NULL); unchanged(&f);
|
||||
assert(send_attachment(&f) == -1 && vetoes == 1); sqlite3_commit_hook(f.inst->topo_sqlite_db, NULL, NULL); unchanged(&f);
|
||||
source(&f); publish(&f);
|
||||
const char* triggers[] = {
|
||||
"CREATE TRIGGER reject_preparation BEFORE INSERT ON attachment_keys BEGIN SELECT RAISE(ABORT,'test insert failure'); END",
|
||||
"CREATE TRIGGER reject_preparation BEFORE INSERT ON attachment_keys BEGIN SELECT RAISE(IGNORE); END"
|
||||
};
|
||||
for (unsigned i = 0; i < 2; i++) {
|
||||
source(&f); sql(f.inst->topo_sqlite_db, triggers[i]); assert(send(&f) == -1); unchanged(&f);
|
||||
source(&f); sql(f.inst->topo_sqlite_db, triggers[i]); assert(send_attachment(&f) == -1); unchanged(&f);
|
||||
sql(f.inst->topo_sqlite_db, "DROP TRIGGER reject_preparation"); source(&f); publish(&f);
|
||||
}
|
||||
source(&f); sql(f.inst->topo_sqlite_db, "BEGIN; UPDATE attachment_keys SET ready=7 WHERE channel='900'");
|
||||
assert(send(&f) == -1 && !f.events && !f.submissions && !sqlite3_get_autocommit(f.inst->topo_sqlite_db));
|
||||
assert(send_attachment(&f) == -1 && !f.events && !f.submissions && !sqlite3_get_autocommit(f.inst->topo_sqlite_db));
|
||||
source_preserved(&f); assert(rows(&f) == f.rows);
|
||||
sqlite3_stmt* st = NULL;
|
||||
assert(sqlite3_prepare_v2(f.inst->topo_sqlite_db, "SELECT ready FROM attachment_keys WHERE channel='900'", -1, &st, NULL) == SQLITE_OK);
|
||||
@@ -249,7 +249,7 @@ static void test_sql_controls(void) {
|
||||
/* Submit может вызвать done до возврата send; SQL уже виден reader, результат остаётся единственным. */
|
||||
static void test_inline_failure(void) {
|
||||
struct fixture f; setup(&f); source(&f); fail_submit = 1;
|
||||
assert(!send(&f) && !fail_submit && f.submissions == 1 && f.events == 1 && !f.success);
|
||||
assert(!send_attachment(&f) && !fail_submit && f.submissions == 1 && f.events == 1 && !f.success);
|
||||
assert(rows(&f) == f.rows + 1 && ma_file_size(f.source) < 0); committed(&f, 0);
|
||||
uasync_poll(f.ua, 0); assert(f.events == 1); cleanup(&f);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEDIA, "PASS attachment: inline submit failure after commit transfers source and reports exactly once");
|
||||
@@ -257,17 +257,18 @@ static void test_inline_failure(void) {
|
||||
|
||||
static void fail_from_callback(void* arg) {
|
||||
struct fixture* f = arg; fault = COMMIT; fail_rollback = 1;
|
||||
assert(send(f) == -1 && !fail_rollback && !f->inst->running && !f->submissions && !f->events);
|
||||
assert(send_attachment(f) == -1 && !fail_rollback && !f->inst->running && !f->submissions && !f->events);
|
||||
assert(!sqlite3_get_autocommit(f->inst->topo_sqlite_db)); source_preserved(f);
|
||||
}
|
||||
|
||||
/* Callback только запрашивает stop; владелец после poll уничтожает живое ядро и закрывает БД. */
|
||||
static void test_rollback_failure(void) {
|
||||
struct fixture f; setup(&f); source(&f);
|
||||
assert(uasync_post(f.ua, fail_from_callback, &f) == ERR_OK);
|
||||
struct posted_task* task = u_calloc(1, sizeof(*task)); assert(task);
|
||||
task->callback = fail_from_callback; task->arg = &f; uasync_post_reserved(f.ua, task);
|
||||
while (f.inst->running) uasync_poll(f.ua, 10);
|
||||
assert(f.inst->chat_started && f.inst->chat_core && rows(&f) == f.rows);
|
||||
assert(send(&f) == -1 && !f.events && !f.submissions); source_preserved(&f);
|
||||
assert(send_attachment(&f) == -1 && !f.events && !f.submissions); source_preserved(&f);
|
||||
chat_event_set_handler(f.inst, NULL); utun_instance_destroy(f.inst); f.inst = NULL;
|
||||
assert(rows(&f) == f.rows); uasync_poll(f.ua, 0);
|
||||
assert(sqlite3_close(f.reader) == SQLITE_OK); uasync_destroy(f.ua, 0); active = NULL;
|
||||
|
||||
Reference in new issue
Block a user