1
0

introspection.tcl 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. start_server {tags {"introspection"}} {
  2. test {CLIENT LIST} {
  3. r client list
  4. } {*addr=*:* fd=* age=* idle=* flags=N db=* sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client*}
  5. test {CLIENT LIST with IDs} {
  6. set myid [r client id]
  7. set cl [split [r client list id $myid] "\r\n"]
  8. assert_match "id=$myid*" [lindex $cl 0]
  9. }
  10. test {CLIENT INFO} {
  11. r client info
  12. } {*addr=*:* fd=* age=* idle=* flags=N db=* sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client*}
  13. test {MONITOR can log executed commands} {
  14. set rd [redis_deferring_client]
  15. $rd monitor
  16. assert_match {*OK*} [$rd read]
  17. r set foo bar
  18. r get foo
  19. list [$rd read] [$rd read]
  20. } {*"set" "foo"*"get" "foo"*}
  21. test {MONITOR can log commands issued by the scripting engine} {
  22. set rd [redis_deferring_client]
  23. $rd monitor
  24. $rd read ;# Discard the OK
  25. r eval {redis.call('set',KEYS[1],ARGV[1])} 1 foo bar
  26. assert_match {*eval*} [$rd read]
  27. assert_match {*lua*"set"*"foo"*"bar"*} [$rd read]
  28. }
  29. test {MONITOR supports redacting command arguments} {
  30. set rd [redis_deferring_client]
  31. $rd monitor
  32. $rd read ; # Discard the OK
  33. r migrate [srv 0 host] [srv 0 port] key 9 5000
  34. r migrate [srv 0 host] [srv 0 port] key 9 5000 AUTH user
  35. r migrate [srv 0 host] [srv 0 port] key 9 5000 AUTH2 user password
  36. catch {r auth not-real} _
  37. catch {r auth not-real not-a-password} _
  38. catch {r hello 2 AUTH not-real not-a-password} _
  39. assert_match {*"key"*"9"*"5000"*} [$rd read]
  40. assert_match {*"key"*"9"*"5000"*"(redacted)"*} [$rd read]
  41. assert_match {*"key"*"9"*"5000"*"(redacted)"*"(redacted)"*} [$rd read]
  42. assert_match {*"auth"*"(redacted)"*} [$rd read]
  43. assert_match {*"auth"*"(redacted)"*"(redacted)"*} [$rd read]
  44. assert_match {*"hello"*"2"*"AUTH"*"(redacted)"*"(redacted)"*} [$rd read]
  45. $rd close
  46. } {0} {needs:repl}
  47. test {MONITOR correctly handles multi-exec cases} {
  48. set rd [redis_deferring_client]
  49. $rd monitor
  50. $rd read ; # Discard the OK
  51. # Make sure multi-exec statements are ordered
  52. # correctly
  53. r multi
  54. r set foo bar
  55. r exec
  56. assert_match {*"multi"*} [$rd read]
  57. assert_match {*"set"*"foo"*"bar"*} [$rd read]
  58. assert_match {*"exec"*} [$rd read]
  59. # Make sure we close multi statements on errors
  60. r multi
  61. catch {r syntax error} _
  62. catch {r exec} _
  63. assert_match {*"multi"*} [$rd read]
  64. assert_match {*"exec"*} [$rd read]
  65. $rd close
  66. }
  67. test {CLIENT GETNAME should return NIL if name is not assigned} {
  68. r client getname
  69. } {}
  70. test {CLIENT LIST shows empty fields for unassigned names} {
  71. r client list
  72. } {*name= *}
  73. test {CLIENT SETNAME does not accept spaces} {
  74. catch {r client setname "foo bar"} e
  75. set e
  76. } {ERR*}
  77. test {CLIENT SETNAME can assign a name to this connection} {
  78. assert_equal [r client setname myname] {OK}
  79. r client list
  80. } {*name=myname*}
  81. test {CLIENT SETNAME can change the name of an existing connection} {
  82. assert_equal [r client setname someothername] {OK}
  83. r client list
  84. } {*name=someothername*}
  85. test {After CLIENT SETNAME, connection can still be closed} {
  86. set rd [redis_deferring_client]
  87. $rd client setname foobar
  88. assert_equal [$rd read] "OK"
  89. assert_match {*foobar*} [r client list]
  90. $rd close
  91. # Now the client should no longer be listed
  92. wait_for_condition 50 100 {
  93. [string match {*foobar*} [r client list]] == 0
  94. } else {
  95. fail "Client still listed in CLIENT LIST after SETNAME."
  96. }
  97. }
  98. test {CONFIG save params special case handled properly} {
  99. # No "save" keyword - defaults should apply
  100. start_server {config "minimal.conf"} {
  101. assert_match [r config get save] {save {3600 1 300 100 60 10000}}
  102. }
  103. # First "save" keyword overrides defaults
  104. start_server {config "minimal.conf" overrides {save {100 100}}} {
  105. # Defaults
  106. assert_match [r config get save] {save {100 100}}
  107. }
  108. } {} {external:skip}
  109. test {CONFIG sanity} {
  110. # Do CONFIG GET, CONFIG SET and then CONFIG GET again
  111. # Skip immutable configs, one with no get, and other complicated configs
  112. set skip_configs {
  113. rdbchecksum
  114. daemonize
  115. io-threads-do-reads
  116. tcp-backlog
  117. always-show-logo
  118. syslog-enabled
  119. cluster-enabled
  120. aclfile
  121. unixsocket
  122. pidfile
  123. syslog-ident
  124. appendfilename
  125. supervised
  126. syslog-facility
  127. databases
  128. io-threads
  129. logfile
  130. unixsocketperm
  131. replicaof
  132. slaveof
  133. requirepass
  134. server_cpulist
  135. bio_cpulist
  136. aof_rewrite_cpulist
  137. bgsave_cpulist
  138. set-proc-title
  139. }
  140. if {!$::tls} {
  141. append skip_configs {
  142. tls-prefer-server-ciphers
  143. tls-session-cache-timeout
  144. tls-session-cache-size
  145. tls-session-caching
  146. tls-cert-file
  147. tls-key-file
  148. tls-client-cert-file
  149. tls-client-key-file
  150. tls-dh-params-file
  151. tls-ca-cert-file
  152. tls-ca-cert-dir
  153. tls-protocols
  154. tls-ciphers
  155. tls-ciphersuites
  156. tls-port
  157. }
  158. }
  159. set configs {}
  160. foreach {k v} [r config get *] {
  161. if {[lsearch $skip_configs $k] != -1} {
  162. continue
  163. }
  164. dict set configs $k $v
  165. # try to set the config to the same value it already has
  166. r config set $k $v
  167. }
  168. set newconfigs {}
  169. foreach {k v} [r config get *] {
  170. if {[lsearch $skip_configs $k] != -1} {
  171. continue
  172. }
  173. dict set newconfigs $k $v
  174. }
  175. dict for {k v} $configs {
  176. set vv [dict get $newconfigs $k]
  177. if {$v != $vv} {
  178. fail "config $k mismatch, expecting $v but got $vv"
  179. }
  180. }
  181. }
  182. # Do a force-all config rewrite and make sure we're able to parse
  183. # it.
  184. test {CONFIG REWRITE sanity} {
  185. # Capture state of config before
  186. set configs {}
  187. foreach {k v} [r config get *] {
  188. dict set configs $k $v
  189. }
  190. # Rewrite entire configuration, restart and confirm the
  191. # server is able to parse it and start.
  192. assert_equal [r debug config-rewrite-force-all] "OK"
  193. restart_server 0 true false
  194. wait_done_loading r
  195. # Verify no changes were introduced
  196. dict for {k v} $configs {
  197. assert_equal $v [lindex [r config get $k] 1]
  198. }
  199. } {} {external:skip}
  200. test {CONFIG REWRITE handles save properly} {
  201. r config set save "3600 1 300 100 60 10000"
  202. r config rewrite
  203. restart_server 0 true false
  204. assert_equal [r config get save] {save {3600 1 300 100 60 10000}}
  205. r config set save ""
  206. r config rewrite
  207. restart_server 0 true false
  208. assert_equal [r config get save] {save {}}
  209. start_server {config "minimal.conf"} {
  210. assert_equal [r config get save] {save {3600 1 300 100 60 10000}}
  211. r config set save ""
  212. r config rewrite
  213. restart_server 0 true false
  214. assert_equal [r config get save] {save {}}
  215. }
  216. } {} {external:skip}
  217. # Config file at this point is at a weird state, and includes all
  218. # known keywords. Might be a good idea to avoid adding tests here.
  219. }