commit 31014c2120f7345bbb91c72cb0542f025b76da38
parent 3f6a79cbcea921c0a69f2233d9daec6c55b15cae
Author: William Casarin <jb55@jb55.com>
Date: Wed, 22 Oct 2025 09:27:00 -0700
test: use wait_for_notes from ndb
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
1 file changed, 11 insertions(+), 27 deletions(-)
diff --git a/src/render.rs b/src/render.rs
@@ -844,10 +844,10 @@ mod tests {
use super::*;
use nostr::nips::nip01::Coordinate;
use nostr::prelude::{EventBuilder, Keys, Tag};
- use nostrdb::Config;
+ use nostrdb::{Config, Filter};
use std::fs;
use std::path::PathBuf;
- use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
+ use std::time::{SystemTime, UNIX_EPOCH};
fn temp_db_dir(prefix: &str) -> PathBuf {
let base = PathBuf::from("target/test-dbs");
@@ -861,23 +861,6 @@ mod tests {
dir
}
- fn wait_for_note(ndb: &Ndb, note_id: &[u8; 32]) {
- let deadline = Instant::now() + Duration::from_millis(500);
- loop {
- if let Ok(txn) = Transaction::new(ndb) {
- if ndb.get_note_by_id(&txn, note_id).is_ok() {
- return;
- }
- }
-
- if Instant::now() >= deadline {
- panic!("timed out waiting for note ingestion");
- }
-
- std::thread::sleep(Duration::from_millis(10));
- }
- }
-
#[test]
fn build_address_filter_includes_only_d_tags() {
let author = [1u8; 32];
@@ -905,8 +888,8 @@ mod tests {
assert!(saw_d_tag, "expected filter to include a 'd' tag constraint");
}
- #[test]
- fn query_note_by_address_uses_d_and_a_tag_filters() {
+ #[tokio::test]
+ async fn query_note_by_address_uses_d_and_a_tag_filters() {
let keys = Keys::generate();
let author = keys.public_key().to_bytes();
let kind = Kind::LongFormTextNote.as_u16() as u64;
@@ -930,28 +913,29 @@ mod tests {
.sign_with_keys(&keys)
.expect("sign long-form event with coordinate tag");
+ let wait_filter = Filter::new().ids([event_with_d.id.as_bytes()]).build();
+ let wait_filter_2 = Filter::new().ids([event_with_a_only.id.as_bytes()]).build();
+
ndb.process_event(&serde_json::to_string(&event_with_d).unwrap())
.expect("ingest event with d tag");
ndb.process_event(&serde_json::to_string(&event_with_a_only).unwrap())
.expect("ingest event with a tag");
- let event_with_d_id = event_with_d.id.to_bytes();
- let event_with_a_only_id = event_with_a_only.id.to_bytes();
- wait_for_note(&ndb, &event_with_d_id);
- wait_for_note(&ndb, &event_with_a_only_id);
+ let sub_id = ndb.subscribe(&[wait_filter, wait_filter_2]).expect("sub");
+ let _r = ndb.wait_for_notes(sub_id, 2).await;
{
let txn = Transaction::new(&ndb).expect("transaction for d-tag lookup");
let note = query_note_by_address(&ndb, &txn, &author, kind, identifier_with_d)
.expect("should find event by d tag");
- assert_eq!(note.id(), &event_with_d_id);
+ assert_eq!(note.id(), event_with_d.id.as_bytes());
}
{
let txn = Transaction::new(&ndb).expect("transaction for a-tag lookup");
let note = query_note_by_address(&ndb, &txn, &author, kind, identifier_with_a)
.expect("should find event via a-tag fallback");
- assert_eq!(note.id(), &event_with_a_only_id);
+ assert_eq!(note.id(), event_with_a_only.id.as_bytes());
}
drop(ndb);