1
0

other.tcl 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. start_server {tags {"other"}} {
  2. if {$::force_failure} {
  3. # This is used just for test suite development purposes.
  4. test {Failing test} {
  5. format err
  6. } {ok}
  7. }
  8. test {SAVE - make sure there are all the types as values} {
  9. # Wait for a background saving in progress to terminate
  10. waitForBgsave r
  11. r lpush mysavelist hello
  12. r lpush mysavelist world
  13. r set myemptykey {}
  14. r set mynormalkey {blablablba}
  15. r zadd mytestzset 10 a
  16. r zadd mytestzset 20 b
  17. r zadd mytestzset 30 c
  18. r save
  19. } {OK} {needs:save}
  20. tags {slow} {
  21. if {$::accurate} {set iterations 10000} else {set iterations 1000}
  22. foreach fuzztype {binary alpha compr} {
  23. test "FUZZ stresser with data model $fuzztype" {
  24. set err 0
  25. for {set i 0} {$i < $iterations} {incr i} {
  26. set fuzz [randstring 0 512 $fuzztype]
  27. r set foo $fuzz
  28. set got [r get foo]
  29. if {$got ne $fuzz} {
  30. set err [list $fuzz $got]
  31. break
  32. }
  33. }
  34. set _ $err
  35. } {0}
  36. }
  37. }
  38. test {BGSAVE} {
  39. waitForBgsave r
  40. r flushdb
  41. r save
  42. r set x 10
  43. r bgsave
  44. waitForBgsave r
  45. r debug reload
  46. r get x
  47. } {10} {needs:save}
  48. test {SELECT an out of range DB} {
  49. catch {r select 1000000} err
  50. set _ $err
  51. } {*index is out of range*} {cluster:skip}
  52. test {EXPIRES after a reload (snapshot + append only file rewrite)} {
  53. r flushdb
  54. r set x 10
  55. r expire x 1000
  56. r save
  57. r debug reload
  58. set ttl [r ttl x]
  59. set e1 [expr {$ttl > 900 && $ttl <= 1000}]
  60. r bgrewriteaof
  61. waitForBgrewriteaof r
  62. r debug loadaof
  63. set ttl [r ttl x]
  64. set e2 [expr {$ttl > 900 && $ttl <= 1000}]
  65. list $e1 $e2
  66. } {1 1} {needs:debug needs:save}
  67. test {EXPIRES after AOF reload (without rewrite)} {
  68. r flushdb
  69. r config set appendonly yes
  70. r config set aof-use-rdb-preamble no
  71. r set x somevalue
  72. r expire x 1000
  73. r setex y 2000 somevalue
  74. r set z somevalue
  75. r expireat z [expr {[clock seconds]+3000}]
  76. # Milliseconds variants
  77. r set px somevalue
  78. r pexpire px 1000000
  79. r psetex py 2000000 somevalue
  80. r set pz somevalue
  81. r pexpireat pz [expr {([clock seconds]+3000)*1000}]
  82. # Reload and check
  83. waitForBgrewriteaof r
  84. # We need to wait two seconds to avoid false positives here, otherwise
  85. # the DEBUG LOADAOF command may read a partial file.
  86. # Another solution would be to set the fsync policy to no, since this
  87. # prevents write() to be delayed by the completion of fsync().
  88. after 2000
  89. r debug loadaof
  90. set ttl [r ttl x]
  91. assert {$ttl > 900 && $ttl <= 1000}
  92. set ttl [r ttl y]
  93. assert {$ttl > 1900 && $ttl <= 2000}
  94. set ttl [r ttl z]
  95. assert {$ttl > 2900 && $ttl <= 3000}
  96. set ttl [r ttl px]
  97. assert {$ttl > 900 && $ttl <= 1000}
  98. set ttl [r ttl py]
  99. assert {$ttl > 1900 && $ttl <= 2000}
  100. set ttl [r ttl pz]
  101. assert {$ttl > 2900 && $ttl <= 3000}
  102. r config set appendonly no
  103. } {OK} {needs:debug}
  104. test {APPEND basics} {
  105. r del foo
  106. list [r append foo bar] [r get foo] \
  107. [r append foo 100] [r get foo]
  108. } {3 bar 6 bar100}
  109. test {APPEND basics, integer encoded values} {
  110. set res {}
  111. r del foo
  112. r append foo 1
  113. r append foo 2
  114. lappend res [r get foo]
  115. r set foo 1
  116. r append foo 2
  117. lappend res [r get foo]
  118. } {12 12}
  119. test {APPEND fuzzing} {
  120. set err {}
  121. foreach type {binary alpha compr} {
  122. set buf {}
  123. r del x
  124. for {set i 0} {$i < 1000} {incr i} {
  125. set bin [randstring 0 10 $type]
  126. append buf $bin
  127. r append x $bin
  128. }
  129. if {$buf != [r get x]} {
  130. set err "Expected '$buf' found '[r get x]'"
  131. break
  132. }
  133. }
  134. set _ $err
  135. } {}
  136. # Leave the user with a clean DB before to exit
  137. test {FLUSHDB} {
  138. set aux {}
  139. if {$::singledb} {
  140. r flushdb
  141. lappend aux 0 [r dbsize]
  142. } else {
  143. r select 9
  144. r flushdb
  145. lappend aux [r dbsize]
  146. r select 10
  147. r flushdb
  148. lappend aux [r dbsize]
  149. }
  150. } {0 0}
  151. test {Perform a final SAVE to leave a clean DB on disk} {
  152. waitForBgsave r
  153. r save
  154. } {OK} {needs:save}
  155. test {RESET clears and discards MULTI state} {
  156. r multi
  157. r set key-a a
  158. r reset
  159. catch {r exec} err
  160. assert_match {*EXEC without MULTI*} $err
  161. } {} {needs:reset}
  162. test {RESET clears Pub/Sub state} {
  163. r subscribe channel-1
  164. r reset
  165. # confirm we're not subscribed by executing another command
  166. r set key val
  167. } {OK} {needs:reset}
  168. }
  169. start_server {tags {"other external:skip"}} {
  170. test {Don't rehash if redis has child proecess} {
  171. r config set save ""
  172. r config set rdb-key-save-delay 1000000
  173. populate 4096 "" 1
  174. r bgsave
  175. wait_for_condition 10 100 {
  176. [s rdb_bgsave_in_progress] eq 1
  177. } else {
  178. fail "bgsave did not start in time"
  179. }
  180. r mset k1 v1 k2 v2
  181. # Hash table should not rehash
  182. assert_no_match "*table size: 8192*" [r debug HTSTATS 9]
  183. exec kill -9 [get_child_pid 0]
  184. after 200
  185. # Hash table should rehash since there is no child process,
  186. # size is power of two and over 4098, so it is 8192
  187. r set k3 v3
  188. assert_match "*table size: 8192*" [r debug HTSTATS 9]
  189. } {} {needs:local-process}
  190. }
  191. proc read_proc_title {pid} {
  192. set fd [open "/proc/$pid/cmdline" "r"]
  193. set cmdline [read $fd 1024]
  194. close $fd
  195. return $cmdline
  196. }
  197. start_server {tags {"other external:skip"}} {
  198. test {Process title set as expected} {
  199. # Test only on Linux where it's easy to get cmdline without relying on tools.
  200. # Skip valgrind as it messes up the arguments.
  201. set os [exec uname]
  202. if {$os == "Linux" && !$::valgrind} {
  203. # Set a custom template
  204. r config set "proc-title-template" "TEST {title} {listen-addr} {port} {tls-port} {unixsocket} {config-file}"
  205. set cmdline [read_proc_title [srv 0 pid]]
  206. assert_equal "TEST" [lindex $cmdline 0]
  207. assert_match "*/redis-server" [lindex $cmdline 1]
  208. if {$::tls} {
  209. set expect_port 0
  210. set expect_tls_port [srv 0 port]
  211. } else {
  212. set expect_port [srv 0 port]
  213. set expect_tls_port 0
  214. }
  215. set port [srv 0 port]
  216. assert_equal "$::host:$port" [lindex $cmdline 2]
  217. assert_equal $expect_port [lindex $cmdline 3]
  218. assert_equal $expect_tls_port [lindex $cmdline 4]
  219. assert_match "*/tests/tmp/server.*/socket" [lindex $cmdline 5]
  220. assert_match "*/tests/tmp/redis.conf.*" [lindex $cmdline 6]
  221. # Try setting a bad template
  222. catch {r config set "proc-title-template" "{invalid-var}"} err
  223. assert_match {*template format is invalid*} $err
  224. }
  225. }
  226. }