mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-12-25 03:20:32 +00:00
Fix search::tests::search to use searcher directly instead of actor
This commit is contained in:
parent
68d79bfa9c
commit
31418b1079
2 changed files with 7 additions and 23 deletions
|
@ -316,10 +316,6 @@ mod tests {
|
||||||
db_conn::DbConn((*DB_POOL).get().unwrap())
|
db_conn::DbConn((*DB_POOL).get().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn pool() -> &'static db_conn::DbPool {
|
|
||||||
&*DB_POOL
|
|
||||||
}
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref DB_POOL: db_conn::DbPool = {
|
static ref DB_POOL: db_conn::DbPool = {
|
||||||
let pool = db_conn::DbPool::builder()
|
let pool = db_conn::DbPool::builder()
|
||||||
|
|
|
@ -8,21 +8,20 @@ pub use self::tokenizer::TokenizerKind;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
use super::{actor::SearchActor, Query, Searcher, TokenizerKind};
|
use super::{Query, Searcher};
|
||||||
use crate::{
|
use crate::{
|
||||||
blogs::tests::fill_database,
|
blogs::tests::fill_database,
|
||||||
config::SearchTokenizerConfig,
|
config::SearchTokenizerConfig,
|
||||||
post_authors::*,
|
post_authors::*,
|
||||||
posts::{NewPost, Post},
|
posts::{NewPost, Post},
|
||||||
safe_string::SafeString,
|
safe_string::SafeString,
|
||||||
tests::pool,
|
tests::db,
|
||||||
CONFIG,
|
CONFIG,
|
||||||
};
|
};
|
||||||
use diesel::Connection;
|
use diesel::Connection;
|
||||||
use plume_common::utils::random_hex;
|
use plume_common::utils::random_hex;
|
||||||
use std::env::temp_dir;
|
use std::env::temp_dir;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub(crate) fn get_searcher(tokenizers: &SearchTokenizerConfig) -> Searcher {
|
pub(crate) fn get_searcher(tokenizers: &SearchTokenizerConfig) -> Searcher {
|
||||||
let dir = temp_dir().join(&format!("plume-test-{}", random_hex()));
|
let dir = temp_dir().join(&format!("plume-test-{}", random_hex()));
|
||||||
|
@ -120,23 +119,11 @@ pub(crate) mod tests {
|
||||||
Searcher::open(&dir, &CONFIG.search_tokenizers).unwrap(); //verify it's well created
|
Searcher::open(&dir, &CONFIG.search_tokenizers).unwrap(); //verify it's well created
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
This assetions fails but I don't know why.
|
|
||||||
`test_transaction()` doesn't commit the transaction and
|
|
||||||
searcher working on the other thread cannot retrieve the result.
|
|
||||||
But, even when we use real `transaction()`, the searcher cannot retrieve.
|
|
||||||
I don't know why, but in the Plume process, it works.
|
|
||||||
It failes only when testing.
|
|
||||||
*/
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
|
||||||
fn search() {
|
fn search() {
|
||||||
let pool = pool();
|
let conn = &db();
|
||||||
let conn = &pool.get().unwrap();
|
|
||||||
|
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let searcher = Arc::new(get_searcher(&CONFIG.search_tokenizers));
|
let searcher = get_searcher(&CONFIG.search_tokenizers);
|
||||||
SearchActor::init(searcher.clone(), pool.clone());
|
|
||||||
let blog = &fill_database(conn).1[0];
|
let blog = &fill_database(conn).1[0];
|
||||||
let author = &blog.list_authors(conn).unwrap()[0];
|
let author = &blog.list_authors(conn).unwrap()[0];
|
||||||
|
|
||||||
|
@ -167,7 +154,7 @@ pub(crate) mod tests {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
searcher.add_document(&conn, &post).unwrap();
|
||||||
searcher.commit();
|
searcher.commit();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
searcher.search_document(conn, Query::from_str(&title).unwrap(), (0, 1))[0].id,
|
searcher.search_document(conn, Query::from_str(&title).unwrap(), (0, 1))[0].id,
|
||||||
|
@ -177,6 +164,7 @@ pub(crate) mod tests {
|
||||||
let newtitle = random_hex()[..8].to_owned();
|
let newtitle = random_hex()[..8].to_owned();
|
||||||
post.title = newtitle.clone();
|
post.title = newtitle.clone();
|
||||||
post.update(conn).unwrap();
|
post.update(conn).unwrap();
|
||||||
|
searcher.update_document(conn, &post).unwrap();
|
||||||
searcher.commit();
|
searcher.commit();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
searcher.search_document(conn, Query::from_str(&newtitle).unwrap(), (0, 1))[0].id,
|
searcher.search_document(conn, Query::from_str(&newtitle).unwrap(), (0, 1))[0].id,
|
||||||
|
@ -186,7 +174,7 @@ pub(crate) mod tests {
|
||||||
.search_document(conn, Query::from_str(&title).unwrap(), (0, 1))
|
.search_document(conn, Query::from_str(&title).unwrap(), (0, 1))
|
||||||
.is_empty());
|
.is_empty());
|
||||||
|
|
||||||
post.delete(conn).unwrap();
|
searcher.delete_document(&post);
|
||||||
searcher.commit();
|
searcher.commit();
|
||||||
assert!(searcher
|
assert!(searcher
|
||||||
.search_document(conn, Query::from_str(&newtitle).unwrap(), (0, 1))
|
.search_document(conn, Query::from_str(&newtitle).unwrap(), (0, 1))
|
||||||
|
|
Loading…
Reference in a new issue