1
0

infotest.tcl 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. set testmodule [file normalize tests/modules/infotest.so]
  2. # Return value for INFO property
  3. proc field {info property} {
  4. if {[regexp "\r\n$property:(.*?)\r\n" $info _ value]} {
  5. set _ $value
  6. }
  7. }
  8. start_server {tags {"modules"}} {
  9. r module load $testmodule log-key 0
  10. test {module reading info} {
  11. # check string, integer and float fields
  12. assert_equal [r info.gets replication role] "master"
  13. assert_equal [r info.getc replication role] "master"
  14. assert_equal [r info.geti stats expired_keys] 0
  15. assert_equal [r info.getd stats expired_stale_perc] 0
  16. # check signed and unsigned
  17. assert_equal [r info.geti infotest infotest_global] -2
  18. assert_equal [r info.getu infotest infotest_uglobal] -2
  19. # the above are always 0, try module info that is non-zero
  20. assert_equal [r info.geti infotest_italian infotest_due] 2
  21. set tre [r info.getd infotest_italian infotest_tre]
  22. assert {$tre > 3.2 && $tre < 3.4 }
  23. # search using the wrong section
  24. catch { [r info.gets badname redis_version] } e
  25. assert_match {*not found*} $e
  26. # check that section filter works
  27. assert { [string match "*usec_per_call*" [r info.gets all cmdstat_info.gets] ] }
  28. catch { [r info.gets default cmdstat_info.gets] ] } e
  29. assert_match {*not found*} $e
  30. }
  31. test {module info all} {
  32. set info [r info all]
  33. # info all does not contain modules
  34. assert { ![string match "*Spanish*" $info] }
  35. assert { ![string match "*infotest_*" $info] }
  36. assert { [string match "*used_memory*" $info] }
  37. }
  38. test {module info everything} {
  39. set info [r info everything]
  40. # info everything contains all default sections, but not ones for crash report
  41. assert { [string match "*infotest_global*" $info] }
  42. assert { [string match "*Spanish*" $info] }
  43. assert { [string match "*Italian*" $info] }
  44. assert { [string match "*used_memory*" $info] }
  45. assert { ![string match "*Klingon*" $info] }
  46. field $info infotest_dos
  47. } {2}
  48. test {module info modules} {
  49. set info [r info modules]
  50. # info all does not contain modules
  51. assert { [string match "*Spanish*" $info] }
  52. assert { [string match "*infotest_global*" $info] }
  53. assert { ![string match "*used_memory*" $info] }
  54. }
  55. test {module info one module} {
  56. set info [r info INFOTEST]
  57. # info all does not contain modules
  58. assert { [string match "*Spanish*" $info] }
  59. assert { ![string match "*used_memory*" $info] }
  60. field $info infotest_global
  61. } {-2}
  62. test {module info one section} {
  63. set info [r info INFOTEST_SPANISH]
  64. assert { ![string match "*used_memory*" $info] }
  65. assert { ![string match "*Italian*" $info] }
  66. assert { ![string match "*infotest_global*" $info] }
  67. field $info infotest_uno
  68. } {one}
  69. test {module info dict} {
  70. set info [r info infotest_keyspace]
  71. set keyspace [field $info infotest_db0]
  72. set keys [scan [regexp -inline {keys\=([\d]*)} $keyspace] keys=%d]
  73. } {3}
  74. test {module info unsafe fields} {
  75. set info [r info infotest_unsafe]
  76. assert_match {*infotest_unsafe_field:value=1*} $info
  77. }
  78. # TODO: test crash report.
  79. }