From 244ebbf1de967fb9aa550be69cab1e2d4d0e50fc Mon Sep 17 00:00:00 2001 From: Chayim Date: Mon, 14 Aug 2023 14:23:25 +0300 Subject: [PATCH] Updating CI to latest redis versions (#163) * Redis version bump for testing * change RC to Uppercase * skip graph tests if version is 7.2.0-RC3 * delete new traits * else if => elif * elif => if * elif * Try somthing * try * try to fix contitions * lessSkipAttr * WIP * Try to use SkipIfRedisVersionLt Attribute * go back * fixes of places with graph * change to SkipIfRedisVersionGte("7.2.0-RC3") * try diif version * try very small version to check if skip * change version to 7.1.242 * Delete trait * one SkipIfRedisVersionAttribute * fix error --------- Co-authored-by: shacharPash <93581407+shacharPash@users.noreply.github.com> Co-authored-by: shacharPash --- .github/workflows/integration.yml | 16 +- tests/NRedisStack.Tests/Gears/GearsTests.cs | 21 +-- tests/NRedisStack.Tests/Graph/GraphTests.cs | 162 +++++++++--------- tests/NRedisStack.Tests/Json/JsonTests.cs | 12 +- tests/NRedisStack.Tests/PipelineTests.cs | 49 +++++- .../SkipIfRedisVersionAttribute.cs | 55 ++++++ tests/NRedisStack.Tests/TransactionsTests.cs | 49 +++++- 7 files changed, 247 insertions(+), 117 deletions(-) create mode 100644 tests/NRedisStack.Tests/SkipIfRedisVersionAttribute.cs diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 7a666e50..02e9f818 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - redis-stack-version: ["6.2.6-v7", "7.0.6-RC8", "edge"] + redis-stack-version: ["6.2.6-v9", "7.2.0-RC3", "edge"] env: USER_NAME: ${{ secrets.USER_NAME }} PASSWORD: ${{ secrets.PASSWORD }} @@ -46,22 +46,14 @@ jobs: echo "${{secrets.REDIS_USER_CRT}}" > tests/NRedisStack.Tests/bin/Debug/net6.0/redis_user.crt echo "${{secrets.REDIS_USER_PRIVATE_KEY}}" > tests/NRedisStack.Tests/bin/Debug/net6.0/redis_user_private.key ls -R - if [ "$REDIS_VERSION" != "edge" ]; then - dotnet test -f net6.0 --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --filter Category!=edge - else - dotnet test -f net6.0 --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover - fi + dotnet test -f net6.0 --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover - name: Test run: | echo "${{secrets.REDIS_CA_PEM}}" > tests/NRedisStack.Tests/bin/Debug/net7.0/redis_ca.pem echo "${{secrets.REDIS_USER_CRT}}" > tests/NRedisStack.Tests/bin/Debug/net7.0/redis_user.crt echo "${{secrets.REDIS_USER_PRIVATE_KEY}}" > tests/NRedisStack.Tests/bin/Debug/net7.0/redis_user_private.key ls -R - if [ "$REDIS_VERSION" != "edge" ]; then - dotnet test -f net7.0 --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --filter Category!=edge - else - dotnet test -f net7.0 --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover - fi + dotnet test -f net7.0 --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover - name: Codecov uses: codecov/codecov-action@v3 with: @@ -105,4 +97,4 @@ jobs: shell: cmd run: | START wsl ./redis-stack-server-${{env.redis_stack_version}}/bin/redis-stack-server & - dotnet test -f net481 --no-build --verbosity normal --filter Category!=edge + dotnet test -f net481 --no-build --verbosity normal diff --git a/tests/NRedisStack.Tests/Gears/GearsTests.cs b/tests/NRedisStack.Tests/Gears/GearsTests.cs index 79d7f7ae..465a65ff 100644 --- a/tests/NRedisStack.Tests/Gears/GearsTests.cs +++ b/tests/NRedisStack.Tests/Gears/GearsTests.cs @@ -16,8 +16,7 @@ public void Dispose() } - [Fact] - [Trait("Category", "edge")] + [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] public void TestTFunctionLoadDelete() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -27,8 +26,7 @@ public void TestTFunctionLoadDelete() } - [Fact] - [Trait("Category", "edge")] + [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] public async Task TestTFunctionLoadDeleteAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -39,8 +37,7 @@ public async Task TestTFunctionLoadDeleteAsync() Assert.True(await db.TFunctionDeleteAsync("lib")); } - [Fact] - [Trait("Category", "edge")] + [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] public void TestTFunctionList() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -71,8 +68,7 @@ public void TestTFunctionList() Assert.True(db.TFunctionDelete("lib3")); } - [Fact] - [Trait("Category", "edge")] + [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] public async Task TestTFunctionListAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -101,8 +97,7 @@ public async Task TestTFunctionListAsync() Assert.True(await db.TFunctionDeleteAsync("lib3")); } - [Fact] - [Trait("Category", "edge")] + [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] public void TestTFCall() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -116,8 +111,7 @@ public void TestTFCall() Assert.True(db.TFunctionDelete("lib")); } - [Fact] - [Trait("Category", "edge")] + [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] public async Task TestTFCallAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -131,8 +125,7 @@ public async Task TestTFCallAsync() Assert.True(await db.TFunctionDeleteAsync("lib")); } - [Fact] - [Trait("Category", "edge")] + [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] public void TestGearsCommandBuilder() { // TFunctionLoad: diff --git a/tests/NRedisStack.Tests/Graph/GraphTests.cs b/tests/NRedisStack.Tests/Graph/GraphTests.cs index d539de78..b7a49c03 100644 --- a/tests/NRedisStack.Tests/Graph/GraphTests.cs +++ b/tests/NRedisStack.Tests/Graph/GraphTests.cs @@ -20,7 +20,7 @@ public void Dispose() #region SyncTests - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestReserveBasic() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -28,7 +28,7 @@ public void TestReserveBasic() var graph = db.GRAPH(); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestCreateNode() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -51,7 +51,7 @@ public void TestCreateNode() graph.Delete("social"); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestCreateLabeledNode() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -72,7 +72,7 @@ public void TestCreateLabeledNode() // Assert.False(resultSet..iterator().MoveNext()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestConnectNodes() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -99,7 +99,7 @@ public void TestConnectNodes() Assert.Equal(0, resultSet.Count); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestDeleteNodes() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -146,7 +146,7 @@ public void TestDeleteNodes() // Assert.False(deleteResult.iterator().MoveNext()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestDeleteRelationship() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -176,7 +176,7 @@ public void TestDeleteRelationship() // Assert.False(deleteResult.iterator().MoveNext()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestIndex() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -203,7 +203,7 @@ public void TestIndex() Assert.Equal(1, deleteExistingIndexResult.Statistics.IndicesDeleted); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestHeader() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -234,7 +234,7 @@ public void TestHeader() Assert.Equal("a.age", schemaNames[2]); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestRecord() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -359,7 +359,7 @@ public void TestRecord() } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestAdditionToProcedures() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -439,7 +439,7 @@ record = iterator.Current; Assert.Equal(expectedEdge.ToString(), record.Values[1].ToString()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestEscapedQuery() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -458,7 +458,7 @@ public void TestEscapedQuery() Assert.NotNull(graph.Query("social", "MATCH (n) where n.s1='S\"' RETURN n")); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestArraySupport() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -558,7 +558,7 @@ record = iterator.Current; } } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestPath() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -610,7 +610,7 @@ public void TestPath() } } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestNullGraphEntities() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -664,7 +664,7 @@ record = resultSet.Skip(1).First(); Assert.Null(record.Values[0]); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void Test64BitNumber() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -682,7 +682,7 @@ public void Test64BitNumber() } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestCachedExecution() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -713,7 +713,7 @@ public void TestCachedExecution() Assert.True(resultSet.Statistics.CachedExecution); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestMapDataType() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -743,7 +743,7 @@ public void TestMapDataType() Assert.Equal((object)expected, actual); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestGeoPointLatLon() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -757,7 +757,7 @@ public void TestGeoPointLatLon() AssertTestGeoPoint(graph); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestGeoPointLonLat() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -786,7 +786,7 @@ private void AssertTestGeoPoint(IGraphCommands graph) Assert.Equal((object)(point), property); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestPoint() { var point = new Point(30.27822306, -97.75134723); @@ -798,7 +798,7 @@ public void TestPoint() Assert.Throws(() => new Point(new List { 1, 2, 3 })); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void timeoutArgument() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -812,7 +812,7 @@ public void timeoutArgument() Assert.Equal(100l, (long)r.Values[0]); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestCachedExecutionReadOnly() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -845,7 +845,7 @@ public void TestCachedExecutionReadOnly() Assert.True(resultSet.Statistics.CachedExecution); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestSimpleReadOnly() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -860,7 +860,7 @@ public void TestSimpleReadOnly() Assert.Equal("30", r.Values[0].ToString()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestProfile() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -878,7 +878,7 @@ public void TestProfile() } } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestExplain() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -896,7 +896,7 @@ public void TestExplain() } } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestSlowlog() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -911,7 +911,7 @@ public void TestSlowlog() slowlogs.ForEach(sl => sl.ForEach(s => Assert.NotNull(s))); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestList() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -924,7 +924,7 @@ public void TestList() Assert.Equal(new List() { "social" }, graph.List()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestConfig() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -944,7 +944,7 @@ public void TestConfig() graph.ConfigSet(name, existingValue != null ? existingValue.ToString() : -1); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestModulePrefixs() { IDatabase db1 = redisFixture.Redis.GetDatabase(); @@ -956,7 +956,7 @@ public void TestModulePrefixs() Assert.NotEqual(graph1.GetHashCode(), graph2.GetHashCode()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestCallProcedureDbLabels() { var db = redisFixture.Redis.GetDatabase(); @@ -977,7 +977,7 @@ public void TestCallProcedureDbLabels() Assert.Single(labels1); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestCallProcedureReadOnly() { var db = redisFixture.Redis.GetDatabase(); @@ -1003,7 +1003,7 @@ public void TestCallProcedureReadOnly() #region AsyncTests - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestReserveBasicAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1011,7 +1011,7 @@ public async Task TestReserveBasicAsync() var graph = db.GRAPH(); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestCreateNodeAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1034,7 +1034,7 @@ public async Task TestCreateNodeAsync() await graph.DeleteAsync("social"); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestCreateLabeledNodeAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1055,7 +1055,7 @@ public async Task TestCreateLabeledNodeAsync() // Assert.False(resultSet..iterator().MoveNext()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestConnectNodesAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1083,7 +1083,7 @@ public async Task TestConnectNodesAsync() // Assert.False(resultSet.GetEnumerator().MoveNext()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestDeleteNodesAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1130,7 +1130,7 @@ public async Task TestDeleteNodesAsync() // Assert.False(deleteResult.iterator().MoveNext()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestDeleteRelationshipAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1160,7 +1160,7 @@ public async Task TestDeleteRelationshipAsync() // Assert.False(deleteResult.iterator().MoveNext()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestIndexAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1187,7 +1187,7 @@ public async Task TestIndexAsync() Assert.Equal(1, deleteExistingIndexResult.Statistics.IndicesDeleted); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestHeaderAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1218,7 +1218,7 @@ public async Task TestHeaderAsync() Assert.Equal("a.age", schemaNames[2]); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestRecordAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1345,7 +1345,7 @@ await graph.QueryAsync("social", "MATCH (a:person), (b:person) WHERE (a.name = ' } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestAdditionToProceduresAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1425,7 +1425,7 @@ record = iterator.Current; Assert.Equal(expectedEdge.ToString(), record.Values[1].ToString()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestEscapedQueryAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1444,7 +1444,7 @@ public async Task TestEscapedQueryAsync() Assert.NotNull(await graph.QueryAsync("social", "MATCH (n) where n.s1='S\"' RETURN n")); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestArraySupportAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1544,7 +1544,7 @@ record = iterator.Current; } } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestPathAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1596,7 +1596,7 @@ public async Task TestPathAsync() } } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestNullGraphEntitiesAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1650,7 +1650,7 @@ record = resultSet.Skip(1).First(); Assert.Null(record.Values[0]); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task Test64bitnumberAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1668,7 +1668,7 @@ public async Task Test64bitnumberAsync() } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestCachedExecutionAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1699,7 +1699,7 @@ public async Task TestCachedExecutionAsync() Assert.True(resultSet.Statistics.CachedExecution); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestMapDataTypeAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1729,7 +1729,7 @@ public async Task TestMapDataTypeAsync() Assert.Equal((object)expected, actual); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestGeoPointLatLonAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1743,7 +1743,7 @@ public async Task TestGeoPointLatLonAsync() AssertTestGeoPoint(graph); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestGeoPointLonLatAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1771,7 +1771,7 @@ private async Task AssertTestGeoPointAsync(GraphCommands graph) Assert.Equal((object)(new Point(30.27822306, -97.75134723)), property); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task timeoutArgumentAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1785,7 +1785,7 @@ public async Task timeoutArgumentAsync() Assert.Equal(100l, (long)r.Values[0]); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestCachedExecutionReadOnlyAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1818,7 +1818,7 @@ public async Task TestCachedExecutionReadOnlyAsync() Assert.True(resultSet.Statistics.CachedExecution); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestSimpleReadOnlyAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1833,7 +1833,7 @@ public async Task TestSimpleReadOnlyAsync() Assert.Equal("30", r.Values[0].ToString()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestProfileAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1851,7 +1851,7 @@ public async Task TestProfileAsync() } } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestExplainAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1869,7 +1869,7 @@ public async Task TestExplainAsync() } } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestSlowlogAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1884,7 +1884,7 @@ public async Task TestSlowlogAsync() slowlogs.ForEach(sl => sl.ForEach(s => Assert.NotNull(s))); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestListAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1897,7 +1897,7 @@ public async Task TestListAsync() Assert.Equal(new List() { "social" }, await graph.ListAsync()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestConfigAsync() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1917,7 +1917,7 @@ public async Task TestConfigAsync() await graph.ConfigSetAsync(name, existingValue != null ? existingValue.ToString() : -1); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestModulePrefixsAsync() { IDatabase db1 = redisFixture.Redis.GetDatabase(); @@ -1929,7 +1929,7 @@ public async Task TestModulePrefixsAsync() Assert.NotEqual(graph1.GetHashCode(), graph2.GetHashCode()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestCallProcedureDbLabelsAsync() { var db = redisFixture.Redis.GetDatabase(); @@ -1950,7 +1950,7 @@ public async Task TestCallProcedureDbLabelsAsync() Assert.Single(labels1); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestCallProcedureReadOnlyAsync() { var db = redisFixture.Redis.GetDatabase(); @@ -1972,7 +1972,7 @@ public async Task TestCallProcedureReadOnlyAsync() await Assert.ThrowsAsync(() => graph.CallProcedureAsync(graphName, "db.idx.fulltext.createNodeIndex", procedureArgs, ProcedureMode.Read)); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestParseInfinity() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -1986,7 +1986,7 @@ public void TestParseInfinity() Assert.Equal(double.PositiveInfinity, r.Values[0]); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestEqualsAndToString() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -2063,7 +2063,7 @@ public void TestEqualsAndToString() Assert.Equal(expectedPathString, pathString); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public void TestPrepareQuery() { const string return1Query = "RETURN 1"; @@ -2072,7 +2072,7 @@ public void TestPrepareQuery() var graph = redisFixture.Redis.GetDatabase().GRAPH(); // handle chars - var buildCommand = GraphCommandBuilder.Query("graph", return1Query, new Dictionary { { "a", (char)'c' }} ); + var buildCommand = GraphCommandBuilder.Query("graph", return1Query, new Dictionary { { "a", (char)'c' } }); var expectedPreparedQuery1 = $"CYPHER a=\"c\" {return1Query}"; Assert.Equal(expectedPreparedQuery1, buildCommand.Args[1].ToString()!); var res1 = graph.Query("graph", buildCommand.Args[1].ToString()!); @@ -2082,64 +2082,64 @@ public void TestPrepareQuery() // handle null var buildCommand2 = GraphCommandBuilder.Query("graph", return1Query, new Dictionary { { "a", null } }); var expectedPreparedQuery2 = $"CYPHER a=null {return1Query}"; - Assert.Equal(expectedPreparedQuery2,buildCommand2.Args[1].ToString()!); - var res2 = graph.Query("graph",buildCommand2.Args[1].ToString()!); + Assert.Equal(expectedPreparedQuery2, buildCommand2.Args[1].ToString()!); + var res2 = graph.Query("graph", buildCommand2.Args[1].ToString()!); Assert.Single(res2); Assert.Equal(return1QueryRecordString, res2.Single().ToString()); // handle arrays var buildCommand3 = GraphCommandBuilder.Query("graph", return1Query, new Dictionary { { "a", new string[] { "foo", "bar" } } }); var expectedPreparedQuery3 = $"CYPHER a=[\"foo\", \"bar\"] {return1Query}"; - Assert.Equal(expectedPreparedQuery3,buildCommand3.Args[1].ToString()!); - var res3 = graph.Query("graph",buildCommand3.Args[1].ToString()!); + Assert.Equal(expectedPreparedQuery3, buildCommand3.Args[1].ToString()!); + var res3 = graph.Query("graph", buildCommand3.Args[1].ToString()!); Assert.Single(res3); Assert.Equal(return1QueryRecordString, res3.Single().ToString()); // handle lists var buildCommand4 = GraphCommandBuilder.Query("graph", return1Query, new Dictionary { { "a", new List { "foo2", "bar2" } } }); var expectedPreparedQuery4 = $"CYPHER a=[\"foo2\", \"bar2\"] {return1Query}"; - Assert.Equal(expectedPreparedQuery4,buildCommand4.Args[1].ToString()!); - var res4 = graph.Query("graph",buildCommand4.Args[1].ToString()!); + Assert.Equal(expectedPreparedQuery4, buildCommand4.Args[1].ToString()!); + var res4 = graph.Query("graph", buildCommand4.Args[1].ToString()!); Assert.Single(res4); Assert.Equal(return1QueryRecordString, res4.Single().ToString()); // handle bools var buildCommand5 = GraphCommandBuilder.Query("graph", return1Query, new Dictionary { { "a", true }, { "b", false } }); var expectedPreparedQuery5 = $"CYPHER a=true b=false {return1Query}"; - Assert.Equal(expectedPreparedQuery5,buildCommand5.Args[1].ToString()!); - var res5 = graph.Query("graph",buildCommand5.Args[1].ToString()!); + Assert.Equal(expectedPreparedQuery5, buildCommand5.Args[1].ToString()!); + var res5 = graph.Query("graph", buildCommand5.Args[1].ToString()!); Assert.Single(res5); Assert.Equal(return1QueryRecordString, res4.Single().ToString()); // handle floats var buildCommand6 = GraphCommandBuilder.Query("graph", return1Query, new Dictionary { { "a", 1.4d } }); var expectedPreparedQuery6 = $"CYPHER a=1.4 {return1Query}"; - Assert.Equal(expectedPreparedQuery6,buildCommand6.Args[1].ToString()!); - var res6 = graph.Query("graph",buildCommand6.Args[1].ToString()!); + Assert.Equal(expectedPreparedQuery6, buildCommand6.Args[1].ToString()!); + var res6 = graph.Query("graph", buildCommand6.Args[1].ToString()!); Assert.Single(res6); Assert.Equal(return1QueryRecordString, res4.Single().ToString()); // handle ints var buildCommand7 = GraphCommandBuilder.Query("graph", return1Query, new Dictionary { { "a", 5 } }); var expectedPreparedQuery7 = $"CYPHER a=5 {return1Query}"; - Assert.Equal(expectedPreparedQuery7,buildCommand7.Args[1].ToString()!); - var res7 = graph.Query("graph",buildCommand7.Args[1].ToString()!); + Assert.Equal(expectedPreparedQuery7, buildCommand7.Args[1].ToString()!); + var res7 = graph.Query("graph", buildCommand7.Args[1].ToString()!); Assert.Single(res7); Assert.Equal(return1QueryRecordString, res4.Single().ToString()); // handle quotes var buildCommand8 = GraphCommandBuilder.Query("graph", return1Query, new Dictionary { { "a", "\"abc\"" } }); var expectedPreparedQuery8 = $"CYPHER a=\"\\\"abc\\\"\" {return1Query}"; - Assert.Equal(expectedPreparedQuery8,buildCommand8.Args[1].ToString()!); - var res8 = graph.Query("graph",buildCommand8.Args[1].ToString()!); + Assert.Equal(expectedPreparedQuery8, buildCommand8.Args[1].ToString()!); + var res8 = graph.Query("graph", buildCommand8.Args[1].ToString()!); Assert.Single(res8); Assert.Equal(return1QueryRecordString, res5.Single().ToString()); // handle backslashes var buildCommand9 = GraphCommandBuilder.Query("graph", return1Query, new Dictionary { { "a", "abc\\" } }); var expectedPreparedQuery9 = $"CYPHER a=\"abc\\\\\" {return1Query}"; - Assert.Equal(expectedPreparedQuery9,buildCommand9.Args[1].ToString()!); - var res9 = graph.Query("graph",buildCommand9.Args[1].ToString()!); + Assert.Equal(expectedPreparedQuery9, buildCommand9.Args[1].ToString()!); + var res9 = graph.Query("graph", buildCommand9.Args[1].ToString()!); Assert.Single(res9); Assert.Equal(return1QueryRecordString, res6.Single().ToString()); } diff --git a/tests/NRedisStack.Tests/Json/JsonTests.cs b/tests/NRedisStack.Tests/Json/JsonTests.cs index f437af67..1ad5ef8a 100644 --- a/tests/NRedisStack.Tests/Json/JsonTests.cs +++ b/tests/NRedisStack.Tests/Json/JsonTests.cs @@ -703,8 +703,7 @@ public async Task GetAsync() Assert.Equal(35, people[1]!.Age); } - [Fact] - [Trait("Category", "edge")] + [SkipIfRedisVersion("7.1.242")] public void MSet() { IJsonCommands commands = new JsonCommands(redisFixture.Redis.GetDatabase()); @@ -728,8 +727,7 @@ public void MSet() Assert.Throws(() => commands.MSet(new KeyPathValue[0])); } - [Fact] - [Trait("Category", "edge")] + [SkipIfRedisVersion("7.1.242")] public async Task MSetAsync() { IJsonCommandsAsync commands = new JsonCommands(redisFixture.Redis.GetDatabase()); @@ -752,8 +750,7 @@ await commands.MSetAsync(values) await Assert.ThrowsAsync(async () => await commands.MSetAsync(new KeyPathValue[0])); } - [Fact] - [Trait("Category", "edge")] + [SkipIfRedisVersion("7.1.242")] public void Merge() { // Create a connection to Redis @@ -772,8 +769,7 @@ public void Merge() Assert.Equal("{\"person\":{\"name\":\"John Doe\",\"phone\":\"123-456-7890\",\"address\":{\"home\":\"123 Main Street\",\"work\":\"Redis office\"}}}", commands.Get("test_merge").ToString()); } - [Fact] - [Trait("Category", "edge")] + [SkipIfRedisVersion("7.1.242")] public async Task MergeAsync() { // Create a connection to Redis diff --git a/tests/NRedisStack.Tests/PipelineTests.cs b/tests/NRedisStack.Tests/PipelineTests.cs index 8eba3289..37ed8dcf 100644 --- a/tests/NRedisStack.Tests/PipelineTests.cs +++ b/tests/NRedisStack.Tests/PipelineTests.cs @@ -18,7 +18,7 @@ public void Dispose() redisFixture.Redis.GetDatabase().KeyDelete(key); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestModulsPipeline() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -69,6 +69,53 @@ public async Task TestModulsPipeline() Assert.NotNull(db.TOPK().Info("topk-key")); } + [Fact] + public async Task TestModulsPipelineWithotGraph() + { + IDatabase db = redisFixture.Redis.GetDatabase(); + db.Execute("FLUSHALL"); + var pipeline = new Pipeline(db); + + pipeline.Bf.ReserveAsync("bf-key", 0.001, 100); + pipeline.Bf.AddAsync("bf-key", "1"); + pipeline.Cms.InitByDimAsync("cms-key", 100, 5); + pipeline.Cf.ReserveAsync("cf-key", 100); + pipeline.Json.SetAsync("json-key", "$", "{}"); + pipeline.Ft.CreateAsync("ft-key", new FTCreateParams(), new Schema().AddTextField("txt")); + pipeline.Tdigest.CreateAsync("tdigest-key", 100); + pipeline.Ts.CreateAsync("ts-key", 100); + pipeline.TopK.ReserveAsync("topk-key", 100, 100, 100); + + Assert.False(db.KeyExists("bf-key")); + Assert.False(db.KeyExists("cms-key")); + Assert.False(db.KeyExists("cf-key")); + Assert.False(db.KeyExists("json-key")); + Assert.Equal(0, db.FT()._List().Length); + Assert.False(db.KeyExists("tdigest-key")); + Assert.False(db.KeyExists("ts-key")); + Assert.False(db.KeyExists("topk-key")); + + pipeline.Execute(); + + Assert.True(db.KeyExists("bf-key")); + Assert.True(db.KeyExists("cms-key")); + Assert.True(db.KeyExists("cf-key")); + Assert.True(db.KeyExists("json-key")); + Assert.True(db.FT()._List().Length == 1); + Assert.True(db.KeyExists("tdigest-key")); + Assert.True(db.KeyExists("ts-key")); + Assert.True(db.KeyExists("topk-key")); + + Assert.True(db.BF().Exists("bf-key", "1")); + Assert.True(db.CMS().Info("cms-key").Width == 100); + Assert.True(db.CF().Info("cf-key").Size > 0); + Assert.False(db.JSON().Get("json-key").IsNull); + Assert.NotNull(db.FT().Info("ft-key")); + Assert.NotNull(db.TDIGEST().Info("tdigest-key")); + Assert.NotNull(db.TS().Info("ts-key")); + Assert.NotNull(db.TOPK().Info("topk-key")); + } + [Fact] public async Task TestBloomPipeline() { diff --git a/tests/NRedisStack.Tests/SkipIfRedisVersionAttribute.cs b/tests/NRedisStack.Tests/SkipIfRedisVersionAttribute.cs new file mode 100644 index 00000000..6d19bc2c --- /dev/null +++ b/tests/NRedisStack.Tests/SkipIfRedisVersionAttribute.cs @@ -0,0 +1,55 @@ +using Xunit; +using StackExchange.Redis; + +public enum Comparison +{ + LessThan, + GreaterThanOrEqual, +} + +[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] +public class SkipIfRedisVersionAttribute : FactAttribute +{ + private readonly string _targetVersion; + private readonly Comparison _comparison; + private readonly string DefaultRedisConnectionString = Environment.GetEnvironmentVariable("REDIS") ?? "localhost:6379"; + + public SkipIfRedisVersionAttribute(string targetVersion) // defaults to LessThan + { + _comparison = Comparison.LessThan; + _targetVersion = targetVersion; + } + + public SkipIfRedisVersionAttribute(Comparison comparison, string targetVersion) + { + _comparison = comparison; + _targetVersion = targetVersion; + } + + public override string Skip + { + get + { + using (var connection = ConnectionMultiplexer.Connect(DefaultRedisConnectionString)) + { + var serverVersion = connection.GetServer(connection.GetEndPoints()[0]).Version; + var targetVersion = new Version(_targetVersion); + int comparisonResult = serverVersion.CompareTo(targetVersion); + + switch (_comparison) + { + case Comparison.LessThan: + if (comparisonResult < 0) + return $"Test skipped because Redis server version ({serverVersion}) is less than {_targetVersion}."; + break; + case Comparison.GreaterThanOrEqual: + if (comparisonResult >= 0) + return $"Test skipped because Redis server version ({serverVersion}) is greater than or equal to {_targetVersion}."; + break; + } + + return null; + } + } + } +} \ No newline at end of file diff --git a/tests/NRedisStack.Tests/TransactionsTests.cs b/tests/NRedisStack.Tests/TransactionsTests.cs index 32533126..f89a8191 100644 --- a/tests/NRedisStack.Tests/TransactionsTests.cs +++ b/tests/NRedisStack.Tests/TransactionsTests.cs @@ -34,7 +34,7 @@ public async Task TestJsonTransaction() Assert.Equal("{\"Name\":\"Shachar\",\"Age\":23}", getResponse.Result.ToString()); } - [Fact] + [SkipIfRedisVersion(Comparison.GreaterThanOrEqual, "7.1.242")] public async Task TestModulsTransaction() { IDatabase db = redisFixture.Redis.GetDatabase(); @@ -84,5 +84,52 @@ public async Task TestModulsTransaction() Assert.NotNull(db.TS().Info("ts-key")); Assert.NotNull(db.TOPK().Info("topk-key")); } + + [Fact] + public async Task TestModulsTransactionWithoutGraph() + { + IDatabase db = redisFixture.Redis.GetDatabase(); + db.Execute("FLUSHALL"); + var tran = new Transaction(db); + + tran.Bf.ReserveAsync("bf-key", 0.001, 100); + tran.Bf.AddAsync("bf-key", "1"); + tran.Cms.InitByDimAsync("cms-key", 100, 5); + tran.Cf.ReserveAsync("cf-key", 100); + tran.Json.SetAsync("json-key", "$", "{}"); + tran.Ft.CreateAsync("ft-key", new FTCreateParams(), new Schema().AddTextField("txt")); + tran.Tdigest.CreateAsync("tdigest-key", 100); + tran.Ts.CreateAsync("ts-key", 100); + tran.TopK.ReserveAsync("topk-key", 100, 100, 100); + + Assert.False(db.KeyExists("bf-key")); + Assert.False(db.KeyExists("cms-key")); + Assert.False(db.KeyExists("cf-key")); + Assert.False(db.KeyExists("json-key")); + Assert.Equal(0, db.FT()._List().Length); + Assert.False(db.KeyExists("tdigest-key")); + Assert.False(db.KeyExists("ts-key")); + Assert.False(db.KeyExists("topk-key")); + + tran.Execute(); + + Assert.True(db.KeyExists("bf-key")); + Assert.True(db.KeyExists("cms-key")); + Assert.True(db.KeyExists("cf-key")); + Assert.True(db.KeyExists("json-key")); + Assert.True(db.FT()._List().Length == 1); + Assert.True(db.KeyExists("tdigest-key")); + Assert.True(db.KeyExists("ts-key")); + Assert.True(db.KeyExists("topk-key")); + + Assert.True(db.BF().Exists("bf-key", "1")); + Assert.True(db.CMS().Info("cms-key").Width == 100); + Assert.True(db.CF().Info("cf-key").Size > 0); + Assert.False(db.JSON().Get("json-key").IsNull); + Assert.NotNull(db.FT().Info("ft-key")); + Assert.NotNull(db.TDIGEST().Info("tdigest-key")); + Assert.NotNull(db.TS().Info("ts-key")); + Assert.NotNull(db.TOPK().Info("topk-key")); + } } }