Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add function mock debug populate #1693

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/support/util.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,10 @@ proc start_write_load {host port seconds} {
proc stop_write_load {handle} {
catch {exec /bin/kill -9 $handle}
}

# Mock debug populate
proc populate {size} {
for {set counter 0} {$counter < $size} {incr counter} {
r set "key:$counter" "key:$counter"
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code patch you provided appears to add a new procedure called "populate" for debug purposes. Here are some observations and suggestions for improvement:

  1. Error handling: It's generally recommended to handle errors gracefully and provide meaningful error messages to users. Currently, the code uses catch to suppress the error when executing /bin/kill -9. Consider adding appropriate error handling or logging in case of any failures.

  2. Magic numbers: The value "-9" in the exec command is a magic number, which might make the code less readable and maintainable. Consider using a named constant or explaining the purpose of this value with a comment.

  3. Code formatting: Ensure consistent code formatting throughout the codebase. Inconsistent indentation can make the code harder to read and maintain. Make sure to use a consistent number of spaces or tabs for indentation.

  4. Variable naming: Consider choosing more descriptive names for variables. For example, instead of using counter, you could use a name that reflects its purpose, such as iteration.

  5. Readability: Enclose expressions involving assignment, increment, and condition checks within parentheses to improve readability. For example, in the populate procedure, the expression $counter < $size would be clearer if written as ($counter < $size).

  6. Use of quotes: Verify whether the current quotation style ("key:$counter") is appropriate for the application context. Depending on the requirements, it may be necessary to use single quotes or escape special characters within the string.

  7. Documentation: Consider adding comments or docstrings to explain the purpose and functionality of the procedures, especially for the newly added populate procedure.

Remember that without having the complete code and context, it's difficult to assess all potential bug risks or suggest further improvements. It's essential to thoroughly test the code after making any changes to ensure its correctness and performance.

11 changes: 6 additions & 5 deletions tests/unit/scan.tcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
start_server {tags {"scan"}} {
test "SCAN basic" {
r flushdb
r debug populate 1000
populate 1000
#populate 1000

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下面这个注释需要保留吗

set cur 0
set keys {}
Expand All @@ -19,7 +20,7 @@ start_server {tags {"scan"}} {

test "SCAN COUNT" {
r flushdb
r debug populate 1000
populate 1000

set cur 0
set keys {}
Expand All @@ -37,7 +38,7 @@ start_server {tags {"scan"}} {

test "SCAN MATCH" {
r flushdb
r debug populate 1000
populate 1000

set cur 0
set keys {}
Expand All @@ -56,7 +57,7 @@ start_server {tags {"scan"}} {
test "SCAN TYPE" {
r flushdb
# populate only creates strings
r debug populate 1000
populate 1000

# Check non-strings are excluded
set cur 0
Expand Down Expand Up @@ -214,7 +215,7 @@ start_server {tags {"scan"}} {

test "SCAN guarantees check under write load" {
r flushdb
r debug populate 100
populate 100

# We start scanning here, so keys from 0 to 99 should all be
# reported at the end of the iteration.
Expand Down