Skip to content

Commit 2aa9e63

Browse files
committed
more search test tweaks
1 parent 5841988 commit 2aa9e63

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tests/NRedisStack.Tests/Search/SearchTests.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ public void TestApplyAndFilterAggregations(string endpointId)
485485
AddDocument(db, new Document("data4").Set("name", "abc").Set("subj1", 30).Set("subj2", 20));
486486
AddDocument(db, new Document("data5").Set("name", "def").Set("subj1", 65).Set("subj2", 45));
487487
AddDocument(db, new Document("data6").Set("name", "ghi").Set("subj1", 70).Set("subj2", 70));
488+
Assert.Equal(6, DatabaseSize(db)); // in part, this is to allow replication to catch up
488489

489490
AggregationRequest r = new AggregationRequest().Apply("(@subj1+@subj2)/2", "attemptavg")
490491
.GroupBy("@name", Reducers.Avg("@attemptavg").As("avgscore"))
@@ -522,6 +523,7 @@ public void TestCreate(string endpointId)
522523
db.HashSet("pupil:4444", [new("first", "Pat"), new("last", "Shu"), new("age", "21")]);
523524
db.HashSet("student:5555", [new("first", "Joen"), new("last", "Ko"), new("age", "20")]);
524525
db.HashSet("teacher:6666", [new("first", "Pat"), new("last", "Rod"), new("age", "20")]);
526+
Assert.Equal(7, DatabaseSize(db)); // in part, this is to allow replication to catch up
525527

526528
var noFilters = ft.Search(index, new());
527529
Assert.Equal(4, noFilters.TotalResults);
@@ -552,6 +554,8 @@ public async Task TestCreateAsync(string endpointId)
552554
db.HashSet("pupil:4444", [new("first", "Pat"), new("last", "Shu"), new("age", "21")]);
553555
db.HashSet("student:5555", [new("first", "Joen"), new("last", "Ko"), new("age", "20")]);
554556
db.HashSet("teacher:6666", [new("first", "Pat"), new("last", "Rod"), new("age", "20")]);
557+
Assert.Equal(7, await DatabaseSizeAsync(db)); // in part, this is to allow replication to catch up
558+
555559
var noFilters = ft.Search(index, new());
556560
Assert.Equal(4, noFilters.TotalResults);
557561
var res1 = ft.Search(index, new("@first:Jo*"));
@@ -576,6 +580,7 @@ public void CreateNoParams(string endpointId)
576580
db.HashSet("student:3333", [new("first", "El"), new("last", "Mark"), new("age", 17)]);
577581
db.HashSet("pupil:4444", [new("first", "Pat"), new("last", "Shu"), new("age", 21)]);
578582
db.HashSet("student:5555", [new("first", "Joen"), new("last", "Ko"), new("age", 20)]);
583+
Assert.Equal(4, DatabaseSize(db)); // in part, this is to allow replication to catch up
579584

580585
SearchResult noFilters = ft.Search(index, new());
581586
Assert.Equal(4, noFilters.TotalResults);
@@ -604,6 +609,7 @@ public async Task CreateNoParamsAsync(string endpointId)
604609
db.HashSet("student:3333", [new("first", "El"), new("last", "Mark"), new("age", 17)]);
605610
db.HashSet("pupil:4444", [new("first", "Pat"), new("last", "Shu"), new("age", 21)]);
606611
db.HashSet("student:5555", [new("first", "Joen"), new("last", "Ko"), new("age", 20)]);
612+
Assert.Equal(4, await DatabaseSizeAsync(db)); // in part, this is to allow replication to catch up
607613

608614
SearchResult noFilters = ft.Search(index, new());
609615
Assert.Equal(4, noFilters.TotalResults);
@@ -1159,6 +1165,7 @@ public async Task TestCursor(string endpointId)
11591165
AddDocument(db, new Document("data1").Set("name", "abc").Set("count", 10));
11601166
AddDocument(db, new Document("data2").Set("name", "def").Set("count", 5));
11611167
AddDocument(db, new Document("data3").Set("name", "def").Set("count", 25));
1168+
Assert.Equal(3, DatabaseSize(db)); // in part, this is to allow replication to catch up
11621169

11631170
AggregationRequest r = new AggregationRequest()
11641171
.GroupBy("@name", Reducers.Sum("@count").As("sum"))
@@ -1213,6 +1220,7 @@ public void TestCursorEnumerable(string endpointId)
12131220
AddDocument(db, new Document("data1").Set("name", "abc").Set("count", 10));
12141221
AddDocument(db, new Document("data2").Set("name", "def").Set("count", 5));
12151222
AddDocument(db, new Document("data3").Set("name", "def").Set("count", 25));
1223+
Assert.Equal(3, DatabaseSize(db)); // in part, this is to allow replication to catch up
12161224

12171225
AggregationRequest r = new AggregationRequest()
12181226
.GroupBy("@name", Reducers.Sum("@count").As("sum"))
@@ -1250,6 +1258,7 @@ public async Task TestCursorAsync(string endpointId)
12501258
AddDocument(db, new Document("data1").Set("name", "abc").Set("count", 10));
12511259
AddDocument(db, new Document("data2").Set("name", "def").Set("count", 5));
12521260
AddDocument(db, new Document("data3").Set("name", "def").Set("count", 25));
1261+
Assert.Equal(3, await DatabaseSizeAsync(db)); // in part, this is to allow replication to catch up
12531262

12541263
AggregationRequest r = new AggregationRequest()
12551264
.GroupBy("@name", Reducers.Sum("@count").As("sum"))
@@ -1304,6 +1313,7 @@ public async Task TestCursorEnumerableAsync(string endpointId)
13041313
AddDocument(db, new Document("data1").Set("name", "abc").Set("count", 10));
13051314
AddDocument(db, new Document("data2").Set("name", "def").Set("count", 5));
13061315
AddDocument(db, new Document("data3").Set("name", "def").Set("count", 25));
1316+
Assert.Equal(3, await DatabaseSizeAsync(db)); // in part, this is to allow replication to catch up
13071317

13081318
AggregationRequest r = new AggregationRequest()
13091319
.GroupBy("@name", Reducers.Sum("@count").As("sum"))
@@ -2265,7 +2275,7 @@ public void TestQueryCommandBuilderScore()
22652275
IDatabase db = GetCleanDatabase();
22662276
var ft = db.FT();
22672277

2268-
db.Execute("JSON.SET", "doc:1", "$", "[{\"arr\": [1, 2, 3]}, {\"val\": \"hello\"}, {\"val\": \"world\"}]");
2278+
db.Execute("JSON.SET", (RedisKey)"doc:1", "$", "[{\"arr\": [1, 2, 3]}, {\"val\": \"hello\"}, {\"val\": \"world\"}]");
22692279
db.Execute("FT.CREATE", "idx", "ON", "JSON", "PREFIX", "1", "doc:", "SCHEMA", "$..arr", "AS", "arr", "NUMERIC", "$..val", "AS", "val", "TEXT");
22702280
// sleep:
22712281
Thread.Sleep(2000);
@@ -2343,6 +2353,7 @@ public void TestLimit(string endpointId)
23432353
Document doc2 = new("doc2", new() { { "t1", "b" }, { "t2", "a" } });
23442354
AddDocument(db, doc1);
23452355
AddDocument(db, doc2);
2356+
Assert.Equal(2, DatabaseSize(db)); // in part, this is to allow replication to catch up
23462357

23472358
var req = new AggregationRequest("*").SortBy("@t1").Limit(1);
23482359
var res = ft.Aggregate("idx", req);
@@ -2363,6 +2374,7 @@ public async Task TestLimitAsync(string endpointId)
23632374
Document doc2 = new("doc2", new() { { "t1", "b" }, { "t2", "a" } });
23642375
AddDocument(db, doc1);
23652376
AddDocument(db, doc2);
2377+
Assert.Equal(2, await DatabaseSizeAsync(db)); // in part, this is to allow replication to catch up
23662378

23672379
var req = new AggregationRequest("*").SortBy("@t1").Limit(1, 1);
23682380
var res = await ft.AggregateAsync("idx", req);
@@ -2447,7 +2459,7 @@ public void VectorSimilaritySearch(string endpointId)
24472459
float[] vec = [2, 2, 2, 2];
24482460
byte[] queryVec = MemoryMarshal.Cast<float, byte>(vec).ToArray();
24492461

2450-
2462+
Assert.Equal(4, DatabaseSize(db)); // in part, this is to allow replication to catch up
24512463
var query = new Query("*=>[KNN 3 @vector $query_vec]")
24522464
.AddParam("query_vec", queryVec)
24532465
.SetSortBy("__vector_score")
@@ -2485,6 +2497,7 @@ public void QueryingVectorFields(string endpointId)
24852497
db.HashSet("b", "v", "aaaabaaa");
24862498
db.HashSet("c", "v", "aaaaabaa");
24872499

2500+
Assert.Equal(3, DatabaseSize(db)); // in part, this is to allow replication to catch up
24882501
var q = new Query("*=>[KNN 2 @v $vec]").ReturnFields("__v_score").Dialect(2);
24892502
var res = ft.Search("idx", q.AddParam("vec", "aaaaaaaa"));
24902503
Assert.Equal(2, res.TotalResults);
@@ -2525,6 +2538,7 @@ public void TestQueryAddParam_DefaultDialect(string endpointId)
25252538
db.HashSet("2", "numval", 2);
25262539
db.HashSet("3", "numval", 3);
25272540

2541+
Assert.Equal(3, DatabaseSize(db)); // in part, this is to allow replication to catch up
25282542
Query query = new Query("@numval:[$min $max]").AddParam("min", 1).AddParam("max", 2);
25292543
var res = ft.Search("idx", query);
25302544
Assert.Equal(2, res.TotalResults);
@@ -2544,6 +2558,7 @@ public async Task TestQueryAddParam_DefaultDialectAsync(string endpointId)
25442558
db.HashSet("2", "numval", 2);
25452559
db.HashSet("3", "numval", 3);
25462560

2561+
Assert.Equal(3, await DatabaseSizeAsync(db)); // in part, this is to allow replication to catch up
25472562
Query query = new Query("@numval:[$min $max]").AddParam("min", 1).AddParam("max", 2);
25482563
var res = await ft.SearchAsync("idx", query);
25492564
Assert.Equal(2, res.TotalResults);
@@ -2563,6 +2578,7 @@ public void TestQueryParamsWithParams_DefaultDialect(string endpointId)
25632578
db.HashSet("2", "numval", 2);
25642579
db.HashSet("3", "numval", 3);
25652580

2581+
Assert.Equal(3, DatabaseSize(db)); // in part, this is to allow replication to catch up
25662582
Query query = new Query("@numval:[$min $max]").AddParam("min", 1).AddParam("max", 2);
25672583
var res = ft.Search("idx", query);
25682584
Assert.Equal(2, res.TotalResults);
@@ -2590,6 +2606,7 @@ public void TestBasicSpellCheck(string endpointId)
25902606
db.HashSet("doc1", [new("name", "name2"), new("body", "body2")]);
25912607
db.HashSet("doc1", [new("name", "name2"), new("body", "name2")]);
25922608

2609+
Assert.Equal(1, DatabaseSize(db)); // in part, this is to allow replication to catch up
25932610
var reply = ft.SpellCheck(index, "name");
25942611
Assert.Single(reply.Keys);
25952612
Assert.Equal("name", reply.Keys.First());
@@ -2610,6 +2627,7 @@ public async Task TestBasicSpellCheckAsync(string endpointId)
26102627
db.HashSet("doc1", [new("name", "name2"), new("body", "body2")]);
26112628
db.HashSet("doc1", [new("name", "name2"), new("body", "name2")]);
26122629

2630+
Assert.Equal(1, await DatabaseSizeAsync(db)); // in part, this is to allow replication to catch up
26132631
var reply = await ft.SpellCheckAsync(index, "name");
26142632
Assert.Single(reply.Keys);
26152633
Assert.Equal("name", reply.Keys.First());
@@ -2723,6 +2741,7 @@ public async Task TestQueryParamsWithParams_DefaultDialectAsync(string endpointI
27232741
db.HashSet("2", "numval", 2);
27242742
db.HashSet("3", "numval", 3);
27252743

2744+
Assert.Equal(3, DatabaseSize(db)); // in part, this is to allow replication to catch up
27262745
Query query = new Query("@numval:[$min $max]").AddParam("min", 1).AddParam("max", 2);
27272746
var res = await ft.SearchAsync("idx", query);
27282747
Assert.Equal(2, res.TotalResults);

0 commit comments

Comments
 (0)