other.tcl 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. list [r append foo bar] [r get foo] \
  180. [r append foo 100] [r get foo]
  181. } {3 bar 6 bar100}
  182. test {APPEND basics, integer encoded values} {
  183. set res {}
  184. r del foo
  185. r append foo 1
  186. r append foo 2
  187. lappend res [r get foo]
  188. r set foo 1
  189. r append foo 2
  190. lappend res [r get foo]
  191. } {12 12}
  192. test {APPEND fuzzing} {
  193. set err {}
  194. foreach type {binary alpha compr} {
  195. set buf {}
  196. r del x
  197. for {set i 0} {$i < 1000} {incr i} {
  198. set bin [randstring 0 10 $type]
  199. append buf $bin
  200. r append x $bin
  201. }
  202. if {$buf != [r get x]} {
  203. set err "Expected '$buf' found '[r get x]'"
  204. break
  205. }
  206. }
  207. set _ $err
  208. } {}
  209. # Leave the user with a clean DB before to exit
  210. test {FLUSHDB} {
  211. set aux {}
  212. r select 9
  213. r flushdb
  214. lappend aux [r dbsize]
  215. r select 10
  216. r flushdb
  217. lappend aux [r dbsize]
  218. } {0 0}
  219. test {Perform a final SAVE to leave a clean DB on disk} {
  220. waitForBgsave r
  221. r save
  222. } {OK}
  223. }