other.tcl 7.2 KB

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