other.tcl 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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}
  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}
  48. test {SELECT an out of range DB} {
  49. catch {r select 1000000} err
  50. set _ $err
  51. } {*index is out of range*}
  52. tags {consistency} {
  53. if {![catch {package require sha1}]} {
  54. if {$::accurate} {set numops 10000} else {set numops 1000}
  55. test {Check consistency of different data types after a reload} {
  56. r flushdb
  57. createComplexDataset r $numops
  58. set dump [csvdump r]
  59. set sha1 [r debug digest]
  60. r debug reload
  61. set sha1_after [r debug digest]
  62. if {$sha1 eq $sha1_after} {
  63. set _ 1
  64. } else {
  65. set newdump [csvdump r]
  66. puts "Consistency test failed!"
  67. puts "You can inspect the two dumps in /tmp/repldump*.txt"
  68. set fd [open /tmp/repldump1.txt w]
  69. puts $fd $dump
  70. close $fd
  71. set fd [open /tmp/repldump2.txt w]
  72. puts $fd $newdump
  73. close $fd
  74. set _ 0
  75. }
  76. } {1}
  77. test {Same dataset digest if saving/reloading as AOF?} {
  78. r config set aof-use-rdb-preamble no
  79. r bgrewriteaof
  80. waitForBgrewriteaof r
  81. r debug loadaof
  82. set sha1_after [r debug digest]
  83. if {$sha1 eq $sha1_after} {
  84. set _ 1
  85. } else {
  86. set newdump [csvdump r]
  87. puts "Consistency test failed!"
  88. puts "You can inspect the two dumps in /tmp/aofdump*.txt"
  89. set fd [open /tmp/aofdump1.txt w]
  90. puts $fd $dump
  91. close $fd
  92. set fd [open /tmp/aofdump2.txt w]
  93. puts $fd $newdump
  94. close $fd
  95. set _ 0
  96. }
  97. } {1}
  98. }
  99. }
  100. test {EXPIRES after a reload (snapshot + append only file rewrite)} {
  101. r flushdb
  102. r set x 10
  103. r expire x 1000
  104. r save
  105. r debug reload
  106. set ttl [r ttl x]
  107. set e1 [expr {$ttl > 900 && $ttl <= 1000}]
  108. r bgrewriteaof
  109. waitForBgrewriteaof r
  110. r debug loadaof
  111. set ttl [r ttl x]
  112. set e2 [expr {$ttl > 900 && $ttl <= 1000}]
  113. list $e1 $e2
  114. } {1 1}
  115. test {EXPIRES after AOF reload (without rewrite)} {
  116. r flushdb
  117. r config set appendonly yes
  118. r config set aof-use-rdb-preamble no
  119. r set x somevalue
  120. r expire x 1000
  121. r setex y 2000 somevalue
  122. r set z somevalue
  123. r expireat z [expr {[clock seconds]+3000}]
  124. # Milliseconds variants
  125. r set px somevalue
  126. r pexpire px 1000000
  127. r psetex py 2000000 somevalue
  128. r set pz somevalue
  129. r pexpireat pz [expr {([clock seconds]+3000)*1000}]
  130. # Reload and check
  131. waitForBgrewriteaof r
  132. # We need to wait two seconds to avoid false positives here, otherwise
  133. # the DEBUG LOADAOF command may read a partial file.
  134. # Another solution would be to set the fsync policy to no, since this
  135. # prevents write() to be delayed by the completion of fsync().
  136. after 2000
  137. r debug loadaof
  138. set ttl [r ttl x]
  139. assert {$ttl > 900 && $ttl <= 1000}
  140. set ttl [r ttl y]
  141. assert {$ttl > 1900 && $ttl <= 2000}
  142. set ttl [r ttl z]
  143. assert {$ttl > 2900 && $ttl <= 3000}
  144. set ttl [r ttl px]
  145. assert {$ttl > 900 && $ttl <= 1000}
  146. set ttl [r ttl py]
  147. assert {$ttl > 1900 && $ttl <= 2000}
  148. set ttl [r ttl pz]
  149. assert {$ttl > 2900 && $ttl <= 3000}
  150. r config set appendonly no
  151. }
  152. tags {protocol} {
  153. test {PIPELINING stresser (also a regression for the old epoll bug)} {
  154. set fd2 [socket $::host $::port]
  155. fconfigure $fd2 -encoding binary -translation binary
  156. puts -nonewline $fd2 "SELECT 9\r\n"
  157. flush $fd2
  158. gets $fd2
  159. for {set i 0} {$i < 100000} {incr i} {
  160. set q {}
  161. set val "0000${i}0000"
  162. append q "SET key:$i $val\r\n"
  163. puts -nonewline $fd2 $q
  164. set q {}
  165. append q "GET key:$i\r\n"
  166. puts -nonewline $fd2 $q
  167. }
  168. flush $fd2
  169. for {set i 0} {$i < 100000} {incr i} {
  170. gets $fd2 line
  171. gets $fd2 count
  172. set count [string range $count 1 end]
  173. set val [read $fd2 $count]
  174. read $fd2 2
  175. }
  176. close $fd2
  177. set _ 1
  178. } {1}
  179. }
  180. test {APPEND basics} {
  181. r del foo
  182. list [r append foo bar] [r get foo] \
  183. [r append foo 100] [r get foo]
  184. } {3 bar 6 bar100}
  185. test {APPEND basics, integer encoded values} {
  186. set res {}
  187. r del foo
  188. r append foo 1
  189. r append foo 2
  190. lappend res [r get foo]
  191. r set foo 1
  192. r append foo 2
  193. lappend res [r get foo]
  194. } {12 12}
  195. test {APPEND fuzzing} {
  196. set err {}
  197. foreach type {binary alpha compr} {
  198. set buf {}
  199. r del x
  200. for {set i 0} {$i < 1000} {incr i} {
  201. set bin [randstring 0 10 $type]
  202. append buf $bin
  203. r append x $bin
  204. }
  205. if {$buf != [r get x]} {
  206. set err "Expected '$buf' found '[r get x]'"
  207. break
  208. }
  209. }
  210. set _ $err
  211. } {}
  212. # Leave the user with a clean DB before to exit
  213. test {FLUSHDB} {
  214. set aux {}
  215. r select 9
  216. r flushdb
  217. lappend aux [r dbsize]
  218. r select 10
  219. r flushdb
  220. lappend aux [r dbsize]
  221. } {0 0}
  222. test {Perform a final SAVE to leave a clean DB on disk} {
  223. waitForBgsave r
  224. r save
  225. } {OK}
  226. }