introspection.tcl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. start_server {tags {"introspection"}} {
  2. test {CLIENT LIST} {
  3. r client list
  4. } {*addr=*:* fd=* age=* idle=* flags=N db=9 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=* obl=0 oll=0 omem=0 events=r cmd=client*}
  5. test {MONITOR can log executed commands} {
  6. set rd [redis_deferring_client]
  7. $rd monitor
  8. assert_match {*OK*} [$rd read]
  9. r set foo bar
  10. r get foo
  11. list [$rd read] [$rd read]
  12. } {*"set" "foo"*"get" "foo"*}
  13. test {MONITOR can log commands issued by the scripting engine} {
  14. set rd [redis_deferring_client]
  15. $rd monitor
  16. $rd read ;# Discard the OK
  17. r eval {redis.call('set',KEYS[1],ARGV[1])} 1 foo bar
  18. assert_match {*eval*} [$rd read]
  19. assert_match {*lua*"set"*"foo"*"bar"*} [$rd read]
  20. }
  21. test {CLIENT GETNAME should return NIL if name is not assigned} {
  22. r client getname
  23. } {}
  24. test {CLIENT LIST shows empty fields for unassigned names} {
  25. r client list
  26. } {*name= *}
  27. test {CLIENT SETNAME does not accept spaces} {
  28. catch {r client setname "foo bar"} e
  29. set e
  30. } {ERR*}
  31. test {CLIENT SETNAME can assign a name to this connection} {
  32. assert_equal [r client setname myname] {OK}
  33. r client list
  34. } {*name=myname*}
  35. test {CLIENT SETNAME can change the name of an existing connection} {
  36. assert_equal [r client setname someothername] {OK}
  37. r client list
  38. } {*name=someothername*}
  39. test {After CLIENT SETNAME, connection can still be closed} {
  40. set rd [redis_deferring_client]
  41. $rd client setname foobar
  42. assert_equal [$rd read] "OK"
  43. assert_match {*foobar*} [r client list]
  44. $rd close
  45. # Now the client should no longer be listed
  46. wait_for_condition 50 100 {
  47. [string match {*foobar*} [r client list]] == 0
  48. } else {
  49. fail "Client still listed in CLIENT LIST after SETNAME."
  50. }
  51. }
  52. test {CONFIG sanity} {
  53. # Do CONFIG GET, CONFIG SET and then CONFIG GET again
  54. # Skip immutable configs, one with no get, and other complicated configs
  55. set skip_configs {
  56. rdbchecksum
  57. daemonize
  58. io-threads-do-reads
  59. tcp-backlog
  60. always-show-logo
  61. syslog-enabled
  62. cluster-enabled
  63. aclfile
  64. unixsocket
  65. pidfile
  66. syslog-ident
  67. appendfilename
  68. supervised
  69. syslog-facility
  70. databases
  71. port
  72. tls-port
  73. io-threads
  74. logfile
  75. unixsocketperm
  76. slaveof
  77. bind
  78. requirepass
  79. server_cpulist
  80. bio_cpulist
  81. aof_rewrite_cpulist
  82. bgsave_cpulist
  83. }
  84. if {!$::tls} {
  85. append skip_configs {
  86. tls-prefer-server-ciphers
  87. tls-session-cache-timeout
  88. tls-session-cache-size
  89. tls-session-caching
  90. tls-cert-file
  91. tls-key-file
  92. tls-dh-params-file
  93. tls-ca-cert-file
  94. tls-ca-cert-dir
  95. tls-protocols
  96. tls-ciphers
  97. tls-ciphersuites
  98. }
  99. }
  100. set configs {}
  101. foreach {k v} [r config get *] {
  102. if {[lsearch $skip_configs $k] != -1} {
  103. continue
  104. }
  105. dict set configs $k $v
  106. # try to set the config to the same value it already has
  107. r config set $k $v
  108. }
  109. set newconfigs {}
  110. foreach {k v} [r config get *] {
  111. if {[lsearch $skip_configs $k] != -1} {
  112. continue
  113. }
  114. dict set newconfigs $k $v
  115. }
  116. dict for {k v} $configs {
  117. set vv [dict get $newconfigs $k]
  118. if {$v != $vv} {
  119. fail "config $k mismatch, expecting $v but got $vv"
  120. }
  121. }
  122. }
  123. }