Skip to content

Commit

Permalink
update testcode
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Sep 6, 2022
1 parent bb46b0e commit 8402a19
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
48 changes: 48 additions & 0 deletions test/Unit/FreeRedis.Tests/RedisClientTests/StreamsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,54 @@ namespace FreeRedis.Tests.RedisClientTests
{
public class StreamsTests : TestBase
{

[Fact]
public void Issues457()
{
var redis = cli;
var key = "key_Issues457";
var group = "group_Issues457";
var consumer = "consumer_Issues457";
var maxLen = 9999;

//删除,重新创建,并加入数据,进行测试
redis.Del(key);
redis.XGroupCreate(key, group, "0", true);
redis.XAdd(key, maxLen, "*", "__data", "my data1");
redis.XAdd(key, maxLen, "*", "__data", "my data2");

//检查pending表的长度
//!!!!!!pending表不存在时,读取会报错!!!!!!!!!
var pending0 = redis.XPending(key, group);
//消费确认前,pending 应该等于0
Assert.True(pending0.count == 0);

//读取未阅读的消息1,读取2次
var new1 = redis.XReadGroup(group, consumer, 1, 1, false, key, ">");
var new2 = redis.XReadGroup(group, consumer, 1, 1, false, key, ">");
Assert.NotNull(new1[0].entries);
Assert.NotEmpty(new1[0].entries);
Assert.NotNull(new2[0].entries);
Assert.NotEmpty(new2[0].entries);

//检查pending表的长度
var pending = redis.XPending(key, group);
//消费确认前,pending 应该等于2
Assert.True(pending.count == 2);

//消费确认
var id1 = new1[0].entries[0].id;
var id2 = new2[0].entries[0].id;
redis.XAck(key, group, id1);
redis.XAck(key, group, id2);

//检查pending表的长度
//!!!!!!pending表不存在时,读取会报错!!!!!!!!!
var pending2 = redis.XPending(key, group);
//消费确认后,pending 应该等于0
//Assert.True(pending2.count == 0);
}

[Fact]
public void XAck()
{
Expand Down
8 changes: 4 additions & 4 deletions test/Unit/FreeRedis.Tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace FreeRedis.Tests
{
public class TestBase
{
protected static ConnectionStringBuilder Connection = new ConnectionStringBuilder()
{
Host = RedisEnvironmentHelper.GetHost("redis_single"),
Password = "123456",
protected static ConnectionStringBuilder Connection = new ConnectionStringBuilder()
{
Host = "192.168.164.10", // RedisEnvironmentHelper.GetHost("redis_single"),
//Password = "123456",
Database = 1,
MaxPoolSize = 10,
Protocol = RedisProtocol.RESP2,
Expand Down

0 comments on commit 8402a19

Please sign in to comment.