protocol.tcl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. if {$::tls} {
  66. set s [::tls::socket [srv 0 host] [srv 0 port]]
  67. } else {
  68. set s [socket [srv 0 host] [srv 0 port]]
  69. }
  70. puts -nonewline $s $seq
  71. set payload [string repeat A 1024]"\n"
  72. set test_start [clock seconds]
  73. set test_time_limit 30
  74. while 1 {
  75. if {[catch {
  76. puts -nonewline $s payload
  77. flush $s
  78. incr payload_size [string length $payload]
  79. }]} {
  80. set retval [gets $s]
  81. close $s
  82. break
  83. } else {
  84. set elapsed [expr {[clock seconds]-$test_start}]
  85. if {$elapsed > $test_time_limit} {
  86. close $s
  87. error "assertion:Redis did not closed connection after protocol desync"
  88. }
  89. }
  90. }
  91. set retval
  92. } {*Protocol error*}
  93. }
  94. unset c
  95. }
  96. start_server {tags {"regression"}} {
  97. test "Regression for a crash with blocking ops and pipelining" {
  98. set rd [redis_deferring_client]
  99. set fd [r channel]
  100. set proto "*3\r\n\$5\r\nBLPOP\r\n\$6\r\nnolist\r\n\$1\r\n0\r\n"
  101. puts -nonewline $fd $proto$proto
  102. flush $fd
  103. set res {}
  104. $rd rpush nolist a
  105. $rd read
  106. $rd rpush nolist a
  107. $rd read
  108. }
  109. }