From c7ec771bcfc55ae98ac2ad0e57bf5b356a2b6516 Mon Sep 17 00:00:00 2001 From: atakavci Date: Mon, 30 Dec 2024 15:57:19 +0300 Subject: [PATCH 1/4] fix failing docuement load in query results with an expired doc --- src/NRedisStack/Search/Document.cs | 4 ++ tests/NRedisStack.Tests/Search/SearchTests.cs | 49 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/NRedisStack/Search/Document.cs b/src/NRedisStack/Search/Document.cs index 3223054f..c8f9dec5 100644 --- a/src/NRedisStack/Search/Document.cs +++ b/src/NRedisStack/Search/Document.cs @@ -31,6 +31,10 @@ public static Document Load(string id, double score, byte[]? payload, RedisValue { Document ret = new Document(id, score, payload); if (fields == null) return ret; + if (fields.Length == 1 && fields[0].IsNull) + { + return ret; + } for (int i = 0; i < fields.Length; i += 2) { string fieldName = fields[i]!; diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index a5acfb68..35ae88df 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -3313,4 +3313,53 @@ public void TestNumericLogicalOperatorsInDialect4() Assert.Equal(1, ft.Search(index, new Query("@version:[123 123] | @id:[456 7890]")).TotalResults); Assert.Equal(1, ft.Search(index, new Query("@version==123 @id==456").Dialect(4)).TotalResults); } + + [Fact] + public void TestDocumentLoad_Issue352() + { + Document d = Document.Load("1", 0.5, null, new RedisValue[] { RedisValue.Null }); + Assert.Empty(d.GetProperties().ToList()); + } + + [Fact] + public void TestDocumentLoadWithDB_Issue352() + { + IDatabase db = redisFixture.Redis.GetDatabase(); + db.Execute("FLUSHALL"); + var ft = db.FT(); + + Schema sc = new Schema().AddTextField("first", 1.0).AddTextField("last", 1.0).AddNumericField("age"); + Assert.True(ft.Create(index, FTCreateParams.CreateParams(), sc)); + + Document droppedDocument = null; + int numberOfAttempts = 0; + do + { + db.HashSet("student:1111", new HashEntry[] { new("first", "Joe"), new("last", "Dod"), new("age", 18) }); + + Assert.True(db.KeyExpire("student:1111", TimeSpan.FromMilliseconds(500))); + + Boolean cancelled = false; + Task searchTask = Task.Run(() => + { + for (int i = 0; i < 100000; i++) + { + SearchResult result = ft.Search(index, new Query()); + List docs = result.Documents; + if (docs.Count == 0 || cancelled) + { + break; + } + else if (docs[0].GetProperties().ToList().Count == 0) + { + droppedDocument = docs[0]; + } + } + }); + Task.WhenAny(searchTask, Task.Delay(1000)).GetAwaiter().GetResult(); + Assert.True(searchTask.IsCompletedSuccessfully); + Assert.Null(searchTask.Exception); + cancelled = true; + } while (droppedDocument == null && numberOfAttempts++ < 3); + } } From 31e478fc993b5733c52dc806bd2e23e6a3d194ed Mon Sep 17 00:00:00 2001 From: atakavci Date: Mon, 30 Dec 2024 16:24:20 +0300 Subject: [PATCH 2/4] IsCompletedSuccessfully" is *not* available in all test envs --- tests/NRedisStack.Tests/Search/SearchTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index 35ae88df..23a09913 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -3357,7 +3357,7 @@ public void TestDocumentLoadWithDB_Issue352() } }); Task.WhenAny(searchTask, Task.Delay(1000)).GetAwaiter().GetResult(); - Assert.True(searchTask.IsCompletedSuccessfully); + Assert.True(searchTask.IsCompleted); Assert.Null(searchTask.Exception); cancelled = true; } while (droppedDocument == null && numberOfAttempts++ < 3); From d0b9e352090973133763803e43cf4cd0d7cbdf66 Mon Sep 17 00:00:00 2001 From: atakavci Date: Mon, 30 Dec 2024 17:02:55 +0300 Subject: [PATCH 3/4] fixing flaky tests in SearchTest by avoiding parallel runs --- tests/NRedisStack.Tests/NoParallelizationCollection.cs | 6 ++++++ tests/NRedisStack.Tests/Search/SearchTests.cs | 1 + 2 files changed, 7 insertions(+) create mode 100644 tests/NRedisStack.Tests/NoParallelizationCollection.cs diff --git a/tests/NRedisStack.Tests/NoParallelizationCollection.cs b/tests/NRedisStack.Tests/NoParallelizationCollection.cs new file mode 100644 index 00000000..523e0e20 --- /dev/null +++ b/tests/NRedisStack.Tests/NoParallelizationCollection.cs @@ -0,0 +1,6 @@ +using Xunit; + +namespace NRedisStack.Tests; + +[CollectionDefinition("NoParallelization", DisableParallelization = true)] +public class NoParallelizationCollection { } diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index 23a09913..893fdfbf 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -12,6 +12,7 @@ namespace NRedisStack.Tests.Search; +[Collection("NoParallelization")] public class SearchTests : AbstractNRedisStackTest, IDisposable { // private readonly string key = "SEARCH_TESTS"; From df4f7f522993aa444d29f032bc69d259ba3bc261 Mon Sep 17 00:00:00 2001 From: atakavci Date: Mon, 30 Dec 2024 18:14:49 +0300 Subject: [PATCH 4/4] set test case for non cluster env --- tests/NRedisStack.Tests/NoParallelizationCollection.cs | 6 ------ tests/NRedisStack.Tests/Search/SearchTests.cs | 4 +--- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 tests/NRedisStack.Tests/NoParallelizationCollection.cs diff --git a/tests/NRedisStack.Tests/NoParallelizationCollection.cs b/tests/NRedisStack.Tests/NoParallelizationCollection.cs deleted file mode 100644 index 523e0e20..00000000 --- a/tests/NRedisStack.Tests/NoParallelizationCollection.cs +++ /dev/null @@ -1,6 +0,0 @@ -using Xunit; - -namespace NRedisStack.Tests; - -[CollectionDefinition("NoParallelization", DisableParallelization = true)] -public class NoParallelizationCollection { } diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index 893fdfbf..c19c7457 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -11,8 +11,6 @@ namespace NRedisStack.Tests.Search; - -[Collection("NoParallelization")] public class SearchTests : AbstractNRedisStackTest, IDisposable { // private readonly string key = "SEARCH_TESTS"; @@ -3322,7 +3320,7 @@ public void TestDocumentLoad_Issue352() Assert.Empty(d.GetProperties().ToList()); } - [Fact] + [SkipIfRedis(Is.OSSCluster)] public void TestDocumentLoadWithDB_Issue352() { IDatabase db = redisFixture.Redis.GetDatabase();