2
0

protocol.tcl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. start_server {tags {"protocol"}} {
  2. test "Handle an empty query" {
  3. reconnect
  4. r write "\r\n"
  5. r flush
  6. assert_equal "PONG" [r ping]
  7. }
  8. test "Negative multibulk length" {
  9. reconnect
  10. r write "*-10\r\n"
  11. r flush
  12. assert_equal PONG [r ping]
  13. }
  14. test "Out of range multibulk length" {
  15. reconnect
  16. r write "*20000000\r\n"
  17. r flush
  18. assert_error "*invalid multibulk length*" {r read}
  19. }
  20. test "Wrong multibulk payload header" {
  21. reconnect
  22. r write "*3\r\n\$3\r\nSET\r\n\$1\r\nx\r\nfooz\r\n"
  23. r flush
  24. assert_error "*expected '$', got 'f'*" {r read}
  25. }
  26. test "Negative multibulk payload length" {
  27. reconnect
  28. r write "*3\r\n\$3\r\nSET\r\n\$1\r\nx\r\n\$-10\r\n"
  29. r flush
  30. assert_error "*invalid bulk length*" {r read}
  31. }
  32. test "Out of range multibulk payload length" {
  33. reconnect
  34. r write "*3\r\n\$3\r\nSET\r\n\$1\r\nx\r\n\$2000000000\r\n"
  35. r flush
  36. assert_error "*invalid bulk length*" {r read}
  37. }
  38. test "Non-number multibulk payload length" {
  39. reconnect
  40. r write "*3\r\n\$3\r\nSET\r\n\$1\r\nx\r\n\$blabla\r\n"
  41. r flush
  42. assert_error "*invalid bulk length*" {r read}
  43. }
  44. test "Multi bulk request not followed by bulk arguments" {
  45. reconnect
  46. r write "*1\r\nfoo\r\n"
  47. r flush
  48. assert_error "*expected '$', got 'f'*" {r read}
  49. }
  50. test "Generic wrong number of args" {
  51. reconnect
  52. assert_error "*wrong*arguments*ping*" {r ping x y z}
  53. }
  54. test "Unbalanced number of quotes" {
  55. reconnect
  56. r write "set \"\"\"test-key\"\"\" test-value\r\n"
  57. r write "ping\r\n"
  58. r flush
  59. assert_error "*unbalanced*" {r read}
  60. }
  61. set c 0
  62. foreach seq [list "\x00" "*\x00" "$\x00"] {
  63. incr c
  64. test "Protocol desync regression test #$c" {
  65. set s [socket [srv 0 host] [srv 0 port]]
  66. puts -nonewline $s $seq
  67. set payload [string repeat A 1024]"\n"
  68. set test_start [clock seconds]
  69. set test_time_limit 30
  70. while 1 {
  71. if {[catch {
  72. puts -nonewline $s payload
  73. flush $s
  74. incr payload_size [string length $payload]
  75. }]} {
  76. set retval [gets $s]
  77. close $s
  78. break
  79. } else {
  80. set elapsed [expr {[clock seconds]-$test_start}]
  81. if {$elapsed > $test_time_limit} {
  82. close $s
  83. error "assertion:Redis did not closed connection after protocol desync"
  84. }
  85. }
  86. }
  87. set retval
  88. } {*Protocol error*}
  89. }
  90. unset c
  91. }
  92. start_server {tags {"regression"}} {
  93. test "Regression for a crash with blocking ops and pipelining" {
  94. set rd [redis_deferring_client]
  95. set fd [r channel]
  96. set proto "*3\r\n\$5\r\nBLPOP\r\n\$6\r\nnolist\r\n\$1\r\n0\r\n"
  97. puts -nonewline $fd $proto$proto
  98. flush $fd
  99. set res {}
  100. $rd rpush nolist a
  101. $rd read
  102. $rd rpush nolist a
  103. $rd read
  104. }
  105. }