nostrdb

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

commit f96beefd5e783bad3c21a20aac07f786ca6a365e
parent 3fff947f57174e2e581b1f53718c5518c6066311
Author: William Casarin <jb55@jb55.com>
Date:   Mon,  7 Aug 2023 17:30:39 -0700

test: add ingest test

Diffstat:
MMakefile | 2+-
Mnostrdb.c | 13+++++++------
Mtest.c | 13++++++++++++-
3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile @@ -19,7 +19,7 @@ all: lib bindings bindings: bindings-swift bindings-c check: test - ./test + ./test | uniq -c clean: rm -rf test bench bindings diff --git a/nostrdb.c b/nostrdb.c @@ -67,7 +67,7 @@ enum ndb_writer_msgtype { }; struct ndb_ingester_event { - const char *json; + char *json; int len; }; @@ -166,12 +166,12 @@ static int ndb_ingester_process_event(secp256k1_context *ctx, } // there's nothing left to do with the original json, so free it - free((void*)ev->json); + free(ev->json); return 1; } cleanup: - free((void*)ev->json); + free(ev->json); free(buf); return 0; @@ -201,7 +201,8 @@ static void *ndb_writer_thread(void *data) ndb_debug("writer: unexpected quit message\n"); goto cleanup; case NDB_WRITER_NOTE: - ndb_debug("writing note %ld bytes\n", msg->note.note_len); + //ndb_debug("writing note %ld bytes\n", msg->note.note_len); + free(msg->note.note); } } @@ -233,7 +234,7 @@ static void *ndb_ingester_thread(void *data) } for (i = 0; i < popped; i++) { - msg = &msg[i]; + msg = &msgs[i]; switch (msg->type) { case NDB_INGEST_QUIT: // quits are handled before this @@ -349,7 +350,7 @@ static int ndb_ingester_destroy(struct ndb_ingester *ingester) } static int ndb_ingester_queue_event(struct ndb_ingester *ingester, - const char *json, int len) + char *json, int len) { struct ndb_ingester_msg msg; msg.type = NDB_INGEST_EVENT; diff --git a/test.c b/test.c @@ -6,15 +6,26 @@ #include <stdio.h> #include <assert.h> +#include <unistd.h> #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) static void test_lmdb_put() { struct ndb *ndb; - + static const int alloc_size = 2 << 18; + char *json = malloc(alloc_size); + int i, written; + // 256MB assert(ndb_init(&ndb, 2 << 28)); + + read_file("testdata/contacts-event.json", (unsigned char*)json, alloc_size, &written); + + for (i = 0; i < 6000; i++) { + ndb_process_event(ndb, json, written); + } + ndb_destroy(ndb); }