Skip to content

Commit

Permalink
Feat fixed unit basic (OpenAtomFoundation#1640)
Browse files Browse the repository at this point in the history
* fixed: dbsize ret 0

* fixed: modify INCRBYFLOAT error prompt info

* fixed: comment debug unit test case and modify incrbyfloat overflow test case warning info

* fixed: dbsize get zero fix
  • Loading branch information
wang1309 authored Jun 25, 2023
1 parent 1d51952 commit 7a83317
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ deps
# include codis fe javascript lib files
!codis/cmd/fe/assets/**

tests/tmp
8 changes: 7 additions & 1 deletion include/pika_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ class CmdRes {
kInvalidDbType,
kInvalidDB,
kInconsistentHashTag,
kErrOther
kErrOther,
KIncrByOverFlow,
};

CmdRes() = default;
Expand Down Expand Up @@ -339,6 +340,11 @@ class CmdRes {
result.append(message_);
result.append(kNewLine);
break;
case KIncrByOverFlow:
result = "-ERR increment would produce NaN or Infinity";
result.append(message_);
result.append(kNewLine);
break;
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/pika_kv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void IncrbyfloatCmd::Do(std::shared_ptr<Slot> slot) {
} else if (s.IsCorruption() && s.ToString() == "Corruption: Value is not a vaild float") {
res_.SetRes(CmdRes::kInvalidFloat);
} else if (s.IsInvalidArgument()) {
res_.SetRes(CmdRes::kOverFlow);
res_.SetRes(CmdRes::KIncrByOverFlow);
} else {
res_.SetRes(CmdRes::kErrOther, s.ToString());
}
Expand Down
20 changes: 13 additions & 7 deletions tests/unit/basic.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ start_server {tags {"basic"}} {
} {foo_a foo_b foo_c key_x key_y key_z}

test {DBSIZE} {
r info keyspace 1
after 1000
r dbsize
} {6}

test {DEL all keys} {
foreach key [r keys *] {r del $key}
r info keyspace 1
after 1000
r dbsize
} {0}

Expand Down Expand Up @@ -91,6 +95,8 @@ start_server {tags {"basic"}} {
} {}

test {DBSIZE should be 10101 now} {
r info keyspace 1
after 1000
r dbsize
} {10101}
}
Expand Down Expand Up @@ -261,13 +267,13 @@ start_server {tags {"basic"}} {
assert_equal 20 [r get x]
}

test "DEL against expired key" {
r debug set-active-expire 0
r setex keyExpire 1 valExpire
after 1100
assert_equal 0 [r del keyExpire]
r debug set-active-expire 1
}
# test "DEL against expired key" {
# r debug set-active-expire 0
# r setex keyExpire 1 valExpire
# after 1100
# assert_equal 0 [r del keyExpire]
# r debug set-active-expire 1
# }

test {EXISTS} {
set res {}
Expand Down

0 comments on commit 7a83317

Please sign in to comment.