Skip to content

Commit

Permalink
Use rstest and enable stable and experimental suggest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jotare committed Dec 20, 2023
1 parent 7a747c0 commit 56ed623
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 42 deletions.
42 changes: 42 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions nucliadb_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ serial_test = "2.0.0"
tempfile = "3.2.0"
regex = "1.5.5"
openssl = { version = "0.10.57", features = ["vendored"] }

rstest = "0.18.2"
116 changes: 74 additions & 42 deletions nucliadb_node/tests/test_suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,34 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

// disable clippy lint caused by rstest proc macro
#![allow(clippy::items_after_test_module)]

mod common;

use std::collections::HashMap;

use common::{resources, NodeFixture, TestNodeReader, TestNodeWriter};
use common::{resources, NodeFixture, TestNodeReader};
use itertools::Itertools;
use nucliadb_core::protos::{
op_status, Filter, NewShardRequest, SuggestFeatures, SuggestRequest, SuggestResponse,
op_status, Filter, NewShardRequest, ReleaseChannel, SuggestFeatures, SuggestRequest,
SuggestResponse,
};
use rstest::*;
use tonic::Request;

#[rstest]
#[awt]
#[tokio::test]
async fn test_suggest_paragraphs() -> Result<(), Box<dyn std::error::Error>> {
let mut fixture = NodeFixture::new();
fixture.with_writer().await?.with_reader().await?;
let mut writer = fixture.writer_client();
let mut reader = fixture.reader_client();

let shard = create_suggest_shard(&mut writer).await;
async fn test_suggest_paragraphs(
#[values(ReleaseChannel::Stable, ReleaseChannel::Experimental)]
_release_channel: ReleaseChannel,
#[future]
#[with(_release_channel)]
suggest_shard: (NodeFixture, ShardDetails),
) -> Result<(), Box<dyn std::error::Error>> {
let (node, shard) = suggest_shard;
let mut reader = node.reader_client();

// exact match
expect_paragraphs(
Expand Down Expand Up @@ -132,14 +141,18 @@ async fn test_suggest_paragraphs() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

#[rstest]
#[awt]
#[tokio::test]
async fn test_suggest_entities() -> Result<(), Box<dyn std::error::Error>> {
let mut fixture = NodeFixture::new();
fixture.with_writer().await?.with_reader().await?;
let mut writer = fixture.writer_client();
let mut reader = fixture.reader_client();

let shard = create_suggest_shard(&mut writer).await;
async fn test_suggest_entities(
#[values(ReleaseChannel::Stable, ReleaseChannel::Experimental)]
_release_channel: ReleaseChannel,
#[future]
#[with(_release_channel)]
suggest_shard: (NodeFixture, ShardDetails),
) -> Result<(), Box<dyn std::error::Error>> {
let (node, shard) = suggest_shard;
let mut reader = node.reader_client();

// basic suggests
expect_entities(
Expand Down Expand Up @@ -196,20 +209,24 @@ async fn test_suggest_entities() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

#[rstest]
#[awt]
#[tokio::test]
async fn test_suggest_features() -> Result<(), Box<dyn std::error::Error>> {
async fn test_suggest_features(
#[values(ReleaseChannel::Stable, ReleaseChannel::Experimental)]
_release_channel: ReleaseChannel,
#[future]
#[with(_release_channel)]
suggest_shard: (NodeFixture, ShardDetails),
) -> Result<(), Box<dyn std::error::Error>> {
// Test: search for "an" with paragraph and entities features and validate
// we search only for what we request.
//
// "an" should match entities starting with this prefix and the "and" word
// from the little prince text

let mut fixture = NodeFixture::new();
fixture.with_writer().await?.with_reader().await?;
let mut writer = fixture.writer_client();
let mut reader = fixture.reader_client();

let shard = create_suggest_shard(&mut writer).await;
let (node, shard) = suggest_shard;
let mut reader = node.reader_client();

let response = suggest_paragraphs(&mut reader, &shard.id, "an").await;
assert!(response.entities.is_none());
Expand All @@ -226,44 +243,59 @@ async fn test_suggest_features() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

struct ShardDetails<'a> {
#[fixture]
fn default_release_channel(
#[default(ReleaseChannel::Stable)] value: ReleaseChannel,
) -> ReleaseChannel {
value
}

struct ShardDetails {
id: String,
resources: HashMap<&'a str, String>,
resources: HashMap<&'static str, String>,
}

async fn create_suggest_shard(writer: &mut TestNodeWriter) -> ShardDetails {
let request = Request::new(NewShardRequest::default());
#[fixture]
async fn suggest_shard(
#[from(default_release_channel)] release_channel: ReleaseChannel,
) -> (NodeFixture, ShardDetails) {
let mut fixture = NodeFixture::new();
fixture.with_writer().await.unwrap();
fixture.with_reader().await.unwrap();

let mut writer = fixture.writer_client();

let request = Request::new(NewShardRequest {
release_channel: release_channel.into(),
..Default::default()
});
let new_shard_response = writer
.new_shard(request)
.await
.expect("Unable to create new shard");
let shard_id = &new_shard_response.get_ref().id;
let resource_uuids = create_test_resources(writer, shard_id.clone()).await;
ShardDetails {
id: shard_id.to_owned(),
resources: resource_uuids,
}
}

async fn create_test_resources(
writer: &mut TestNodeWriter,
shard_id: String,
) -> HashMap<&str, String> {
let resources = [
("little prince", resources::little_prince(&shard_id)),
("zarathustra", resources::thus_spoke_zarathustra(&shard_id)),
("pap", resources::people_and_places(&shard_id)),
("little prince", resources::little_prince(shard_id)),
("zarathustra", resources::thus_spoke_zarathustra(shard_id)),
("pap", resources::people_and_places(shard_id)),
];
let mut resource_uuids = HashMap::new();

let mut resource_uuids = HashMap::new();
for (name, resource) in resources.into_iter() {
resource_uuids.insert(name, resource.resource.as_ref().unwrap().uuid.clone());
let request = Request::new(resource);
let response = writer.set_resource(request).await.unwrap();
assert_eq!(response.get_ref().status, op_status::Status::Ok as i32);
}

resource_uuids
(
fixture,
ShardDetails {
id: shard_id.to_owned(),
resources: resource_uuids,
},
)
}

async fn suggest_paragraphs(
Expand Down

3 comments on commit 56ed623

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 56ed623 Previous: 5a633b0 Ratio
nucliadb/search/tests/unit/search/test_fetch.py::test_highligh_error 13147.206657249422 iter/sec (stddev: 9.689795926417588e-7) 12745.686329086004 iter/sec (stddev: 1.7317806991721728e-7) 0.97

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 56ed623 Previous: 5a633b0 Ratio
nucliadb/search/tests/unit/search/test_fetch.py::test_highligh_error 13169.59258729119 iter/sec (stddev: 6.927142499728491e-7) 12745.686329086004 iter/sec (stddev: 1.7317806991721728e-7) 0.97

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 56ed623 Previous: 5a633b0 Ratio
nucliadb/search/tests/unit/search/test_fetch.py::test_highligh_error 12988.914542615144 iter/sec (stddev: 9.591887204237113e-7) 12745.686329086004 iter/sec (stddev: 1.7317806991721728e-7) 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.