misc.tcl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 keyexists} {
  35. r set x foo
  36. assert_equal 1 [r test.keyexists x]
  37. r del x
  38. assert_equal 0 [r test.keyexists x]
  39. }
  40. test {test module lru api} {
  41. r config set maxmemory-policy allkeys-lru
  42. r set x foo
  43. set lru [r test.getlru x]
  44. assert { $lru <= 1000 }
  45. set was_set [r test.setlru x 100000]
  46. assert { $was_set == 1 }
  47. set idle [r object idletime x]
  48. assert { $idle >= 100 }
  49. set lru [r test.getlru x]
  50. assert { $lru >= 100000 }
  51. r config set maxmemory-policy allkeys-lfu
  52. set lru [r test.getlru x]
  53. assert { $lru == -1 }
  54. set was_set [r test.setlru x 100000]
  55. assert { $was_set == 0 }
  56. }
  57. r config set maxmemory-policy allkeys-lru
  58. test {test module lfu api} {
  59. r config set maxmemory-policy allkeys-lfu
  60. r set x foo
  61. set lfu [r test.getlfu x]
  62. assert { $lfu >= 1 }
  63. set was_set [r test.setlfu x 100]
  64. assert { $was_set == 1 }
  65. set freq [r object freq x]
  66. assert { $freq <= 100 }
  67. set lfu [r test.getlfu x]
  68. assert { $lfu <= 100 }
  69. r config set maxmemory-policy allkeys-lru
  70. set lfu [r test.getlfu x]
  71. assert { $lfu == -1 }
  72. set was_set [r test.setlfu x 100]
  73. assert { $was_set == 0 }
  74. }
  75. test {test module clientinfo api} {
  76. # Test basic sanity and SSL flag
  77. set info [r test.clientinfo]
  78. set ssl_flag [expr $::tls ? {"ssl:"} : {":"}]
  79. assert { [dict get $info db] == 9 }
  80. assert { [dict get $info flags] == "${ssl_flag}::::" }
  81. # Test MULTI flag
  82. r multi
  83. r test.clientinfo
  84. set info [lindex [r exec] 0]
  85. assert { [dict get $info flags] == "${ssl_flag}::::multi" }
  86. # Test TRACKING flag
  87. r client tracking on
  88. set info [r test.clientinfo]
  89. assert { [dict get $info flags] == "${ssl_flag}::tracking::" }
  90. }
  91. test {test module getclientcert api} {
  92. set cert [r test.getclientcert]
  93. if {$::tls} {
  94. assert {$cert != ""}
  95. } else {
  96. assert {$cert == ""}
  97. }
  98. }
  99. test {test detached thread safe cnotext} {
  100. r test.log_tsctx "info" "Test message"
  101. verify_log_message 0 "*<misc> Test message*" 0
  102. }
  103. test {test RM_Call CLIENT INFO} {
  104. assert_match "*fd=-1*" [r test.call_generic client info]
  105. }
  106. }