nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit 115536853cd00b5bc0e6124e6add32f59271ce3b
parent c624f7bee29d41f14dbca24e3234277ab27ab06c
Author: William Casarin <jb55@jb55.com>
Date:   Wed,  3 Jan 2024 12:27:45 -0800

test: switch reaction test to use subscriptions

Diffstat:
Msrc/nostrdb.c | 6++++--
Msrc/nostrdb.h | 1+
Mtest.c | 19+++++++++++++++----
3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/nostrdb.c b/src/nostrdb.c @@ -869,12 +869,14 @@ static void ndb_filter_group_init(struct ndb_filter_group *group) group->num_filters = 0; } -static int ndb_filter_group_add(struct ndb_filter_group *group, +int ndb_filter_group_add(struct ndb_filter_group *group, struct ndb_filter *filter) { - if (group->num_filters + 1 >= NDB_MAX_FILTERS) + if (group->num_filters + 1 > NDB_MAX_FILTERS) return 0; + group->filters[group->num_filters++] = filter; + return 1; } static int ndb_filter_group_matches(struct ndb_filter_group *group, diff --git a/src/nostrdb.h b/src/nostrdb.h @@ -470,6 +470,7 @@ int ndb_filter_start_generic_field(struct ndb_filter *, char tag); int ndb_filter_matches(struct ndb_filter *, struct ndb_note *); void ndb_filter_reset(struct ndb_filter *); void ndb_filter_end_field(struct ndb_filter *); +int ndb_filter_group_add(struct ndb_filter_group *group, struct ndb_filter *f); void ndb_filter_free(struct ndb_filter *); // SUBSCRIPTIONS diff --git a/test.c b/test.c @@ -208,19 +208,30 @@ static void test_reaction_counter() struct ndb *ndb; size_t len; void *root; - int written, reactions; + int written, reactions, results; NdbEventMeta_table_t meta; struct ndb_txn txn; struct ndb_config config; ndb_default_config(&config); + static const int num_reactions = 3; + struct ndb_filter_group group; + uint64_t note_ids[num_reactions], subid; assert(ndb_init(&ndb, test_dir, &config)); read_file("testdata/reactions.json", (unsigned char*)json, alloc_size, &written); + + group.num_filters = 0; + assert((subid = ndb_subscribe(ndb, &group))); + assert(ndb_process_client_events(ndb, json, written)); - ndb_destroy(ndb); - assert(ndb_init(&ndb, test_dir, &config)); + for (reactions = 0; reactions < num_reactions;) { + results = ndb_wait_for_notes(ndb, subid, note_ids, num_reactions); + reactions += results; + fprintf(stderr, "got %d notes, total %d\n", results, reactions); + assert(reactions > 0); + } assert(ndb_begin_query(ndb, &txn)); @@ -1231,7 +1242,7 @@ static void test_subscriptions() assert(ndb_process_event(ndb, ev, strlen(ev))); - assert(ndb_wait_for_notes(ndb, subid, &note_id, 1)); + assert(ndb_wait_for_notes(ndb, subid, &note_id, 1) == 1); assert(ndb_begin_query(ndb, &txn)); assert((note = ndb_get_note_by_key(&txn, note_id, NULL)));