1
0

misc.tcl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. set testmodule [file normalize tests/modules/misc.so]
  2. start_server {tags {"modules"}} {
  3. r module load $testmodule
  4. test {test RM_Call} {
  5. set info [r test.call_info commandstats]
  6. # cmdstat is not in a default section, so we also test an argument was passed
  7. assert { [string match "*cmdstat_module*" $info] }
  8. }
  9. test {test RM_Call args array} {
  10. set info [r test.call_generic info commandstats]
  11. # cmdstat is not in a default section, so we also test an argument was passed
  12. assert { [string match "*cmdstat_module*" $info] }
  13. }
  14. test {test RM_Call recursive} {
  15. set info [r test.call_generic test.call_generic info commandstats]
  16. assert { [string match "*cmdstat_module*" $info] }
  17. }
  18. test {test redis version} {
  19. set version [s redis_version]
  20. assert_equal $version [r test.redisversion]
  21. }
  22. test {test long double conversions} {
  23. set ld [r test.ld_conversion]
  24. assert {[string match $ld "0.00000000000000001"]}
  25. }
  26. test {test module db commands} {
  27. r set x foo
  28. set key [r test.randomkey]
  29. assert_equal $key "x"
  30. assert_equal [r test.dbsize] 1
  31. r test.flushall
  32. assert_equal [r test.dbsize] 0
  33. }
  34. test {test module lru api} {
  35. r config set maxmemory-policy allkeys-lru
  36. r set x foo
  37. set lru [r test.getlru x]
  38. assert { $lru <= 1000 }
  39. set was_set [r test.setlru x 100000]
  40. assert { $was_set == 1 }
  41. set idle [r object idletime x]
  42. assert { $idle >= 100 }
  43. set lru [r test.getlru x]
  44. assert { $lru >= 100000 }
  45. r config set maxmemory-policy allkeys-lfu
  46. set lru [r test.getlru x]
  47. assert { $lru == -1 }
  48. set was_set [r test.setlru x 100000]
  49. assert { $was_set == 0 }
  50. }
  51. r config set maxmemory-policy allkeys-lru
  52. test {test module lfu api} {
  53. r config set maxmemory-policy allkeys-lfu
  54. r set x foo
  55. set lfu [r test.getlfu x]
  56. assert { $lfu >= 1 }
  57. set was_set [r test.setlfu x 100]
  58. assert { $was_set == 1 }
  59. set freq [r object freq x]
  60. assert { $freq <= 100 }
  61. set lfu [r test.getlfu x]
  62. assert { $lfu <= 100 }
  63. r config set maxmemory-policy allkeys-lru
  64. set lfu [r test.getlfu x]
  65. assert { $lfu == -1 }
  66. set was_set [r test.setlfu x 100]
  67. assert { $was_set == 0 }
  68. }
  69. test {test module clientinfo api} {
  70. # Test basic sanity and SSL flag
  71. set info [r test.clientinfo]
  72. set ssl_flag [expr $::tls ? {"ssl:"} : {":"}]
  73. assert { [dict get $info db] == 9 }
  74. assert { [dict get $info flags] == "${ssl_flag}::::" }
  75. # Test MULTI flag
  76. r multi
  77. r test.clientinfo
  78. set info [lindex [r exec] 0]
  79. assert { [dict get $info flags] == "${ssl_flag}::::multi" }
  80. # Test TRACKING flag
  81. r client tracking on
  82. set info [r test.clientinfo]
  83. assert { [dict get $info flags] == "${ssl_flag}::tracking::" }
  84. }
  85. test {test module getclientcert api} {
  86. set cert [r test.getclientcert]
  87. if {$::tls} {
  88. assert {$cert != ""}
  89. } else {
  90. assert {$cert == ""}
  91. }
  92. }
  93. test {test detached thread safe cnotext} {
  94. r test.log_tsctx "info" "Test message"
  95. verify_log_message 0 "*<misc> Test message*" 0
  96. }
  97. test {test RM_Call CLIENT INFO} {
  98. assert_match "*fd=-1*" [r test.call_generic client info]
  99. }
  100. }