-
Notifications
You must be signed in to change notification settings - Fork 687
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
Add tests for src/module examples #1407
Open
Codebells
wants to merge
1
commit into
valkey-io:unstable
Choose a base branch
from
Codebells:fix/src_module_tcl
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,5 @@ then | |
fi | ||
|
||
$MAKE -C tests/modules && \ | ||
$MAKE -C src/modules && \ | ||
$TCLSH tests/test_helper.tcl --moduleapi "${@}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
source tests/support/cli.tcl | ||
|
||
set helloblockmodule [file normalize src/modules/helloblock.so] | ||
set hellodictmodule [file normalize src/modules/hellodict.so] | ||
set hellotimermodule [file normalize src/modules/hellotimer.so] | ||
set hellotypemodule [file normalize src/modules/hellotype.so] | ||
set helloworldmodule [file normalize src/modules/helloworld.so] | ||
|
||
start_server {tags {"modules"}} { | ||
r module load $hellodictmodule | ||
r module load $helloblockmodule | ||
r module load $hellotypemodule | ||
r module load $hellotimermodule | ||
r module load $helloworldmodule | ||
r select 0 | ||
|
||
test {test module command specs} { | ||
check_commands_specs r | ||
} | ||
test {test hellodict} { | ||
foreach i {a b c d e f g h i j k l m n o p q r s t u v w x y z} { | ||
r hellodict.set $i $i | ||
assert_match [r hellodict.get $i] $i | ||
} | ||
assert_equal [llength [r hellodict.keyrange a b 2]] 2 | ||
assert_equal [llength [r hellodict.keyrange a z 2]] 2 | ||
} | ||
|
||
test {test helloblock} { | ||
assert_match [r hello.block 1 2] "Request timedout" | ||
assert {[r hello.block 1 2000] > 0} | ||
r set foo bar | ||
assert {[llength [r hello.keys]] > 0} | ||
r flushall | ||
assert_equal [llength [r hello.keys]] 0 | ||
} | ||
|
||
test {test hellotype} { | ||
set cnt 1 | ||
while {$cnt <= 10000} { | ||
r hellotype.insert hello $cnt | ||
incr cnt | ||
} | ||
assert_equal [llength [r hellotype.range hello 1 100]] 100 | ||
assert_equal [llength [r hellotype.range hello 1 1000]] 1000 | ||
assert_equal [llength [r hellotype.brange hello 1 20000 1]] 10000 | ||
} | ||
|
||
test {test helloworld} { | ||
assert_equal [r hello.simple] 0 | ||
assert_equal [r hello.push.native lkey 1] 1 | ||
assert_equal [r hello.push.call lkey 2] 2 | ||
assert_equal [r hello.push.call2 lkey 3] 3 | ||
assert_equal [r hello.list.sum.len lkey] 3 | ||
assert_equal [r hello.list.splice lkey lkey2 1] 2 | ||
assert_equal [r hello.list.sum.len lkey] 2 | ||
assert_equal [r hello.list.sum.len lkey2] 1 | ||
assert_equal [r hello.list.splice.auto lkey lkey2 1] 1 | ||
assert_equal [r hello.list.sum.len lkey] 1 | ||
assert_equal [r hello.list.sum.len lkey2] 2 | ||
assert_equal [llength [r hello.rand.array 10]] 10 | ||
|
||
r hello.repl1 | ||
r hello.repl1 | ||
assert_equal [r get foo] 2 | ||
assert_equal [r get bar] 2 | ||
|
||
assert_equal [r hello.push.native lsum 1] 1 | ||
assert_equal [r hello.push.call lsum 2] 2 | ||
assert_equal [r hello.push.call2 lsum 3] 3 | ||
assert_equal [r hello.repl2 lsum] 9 | ||
|
||
r set a b | ||
r hello.toggle.case a | ||
assert_equal [r get a] B | ||
r hello.toggle.case a | ||
assert_equal [r get a] b | ||
|
||
r set tk bb EX 100 | ||
assert {[r ttl tk] < 101} | ||
r hello.more.expire tk 1000000000 | ||
assert {[r ttl tk] > 100} | ||
|
||
r zadd myzset 1 a 2 b 3 c 4 d | ||
set res [r hello.zsumrange myzset 1 3] | ||
assert_equal [lindex $res 0] 6 | ||
assert_equal [lindex $res 0] [lindex $res 1] | ||
|
||
r zadd myzset 0 e 0 f 0 g 0 h | ||
set lexres [r hello.lexrange myzset "\[b" "\[f" 0 0] | ||
assert_equal [llength $lexres] 2 | ||
|
||
r hset hkey a a | ||
r hello.hcopy hkey a b | ||
assert_match [r hget hkey a] [r hget hkey b] | ||
|
||
assert_match [r hello.leftpad td 4 0] "00td" | ||
} | ||
|
||
test {unload modules} { | ||
r FLUSHALL | ||
assert_equal {OK} [r module unload hellodict] | ||
assert_equal {OK} [r module unload helloblock] | ||
assert_equal {OK} [r module unload hellotimer] | ||
assert_equal {OK} [r module unload helloworld] | ||
} | ||
} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also do a module unload in the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I try to unload hellotype module, I found there is only
VM_CreateDataType
function, why don't have any function to delete it? So that I can't unload hellotype module, because ofERR Error unloading module: the module exports one or more module-side data types can't unload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think u can skip unload hello_type module