| 1 |
# httpPipeline.test |
| 2 |
# |
| 3 |
# Test HTTP/1.1 concurrent requests including |
| 4 |
# queueing, pipelining and retries. |
| 5 |
# |
| 6 |
# Copyright (C) 2018 Keith Nash <[email protected]> |
| 7 |
# |
| 8 |
# See the file "license.terms" for information on usage and redistribution |
| 9 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 10 |
|
| 11 |
if {"::tcltest" ni [namespace children]} { |
| 12 |
package require tcltest 2.5 |
| 13 |
namespace import -force ::tcltest::* |
| 14 |
} |
| 15 |
|
| 16 |
package require http 2.9 |
| 17 |
|
| 18 |
set sourcedir [file normalize [file dirname [info script]]] |
| 19 |
source [file join $sourcedir httpTest.tcl] |
| 20 |
source [file join $sourcedir httpTestScript.tcl] |
| 21 |
|
| 22 |
# ------------------------------------------------------------------------------ |
| 23 |
# (1) Define the test scripts that will be used to generate logs for analysis - |
| 24 |
# and also define the "correct" results. |
| 25 |
# ------------------------------------------------------------------------------ |
| 26 |
|
| 27 |
proc ReturnTestScriptAndResult {ca cb delay te} { |
| 28 |
|
| 29 |
switch -- $ca { |
| 30 |
1 {set start { |
| 31 |
START |
| 32 |
KEEPALIVE 0 |
| 33 |
PIPELINE 0 |
| 34 |
}} |
| 35 |
|
| 36 |
2 {set start { |
| 37 |
START |
| 38 |
KEEPALIVE 0 |
| 39 |
PIPELINE 1 |
| 40 |
}} |
| 41 |
|
| 42 |
3 {set start { |
| 43 |
START |
| 44 |
KEEPALIVE 1 |
| 45 |
PIPELINE 0 |
| 46 |
}} |
| 47 |
|
| 48 |
4 {set start { |
| 49 |
START |
| 50 |
KEEPALIVE 1 |
| 51 |
PIPELINE 1 |
| 52 |
}} |
| 53 |
|
| 54 |
default { |
| 55 |
return -code error {no matching script} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
set middle " |
| 60 |
[list DELAY $delay] |
| 61 |
" |
| 62 |
|
| 63 |
switch -- $cb { |
| 64 |
1 {set end { |
| 65 |
GET a |
| 66 |
GET b |
| 67 |
GET c |
| 68 |
GET a |
| 69 |
STOP |
| 70 |
} |
| 71 |
set resShort {1 ? ? ?} |
| 72 |
set resLong {1 2 3 4} |
| 73 |
} |
| 74 |
|
| 75 |
2 {set end { |
| 76 |
GET a |
| 77 |
HEAD b |
| 78 |
GET c |
| 79 |
HEAD a |
| 80 |
HEAD c |
| 81 |
STOP |
| 82 |
} |
| 83 |
set resShort {1 ? ? ? ?} |
| 84 |
set resLong {1 2 3 4 5} |
| 85 |
} |
| 86 |
|
| 87 |
3 {set end { |
| 88 |
HEAD a |
| 89 |
GET b |
| 90 |
HEAD c |
| 91 |
HEAD b |
| 92 |
GET a |
| 93 |
GET b |
| 94 |
STOP |
| 95 |
} |
| 96 |
set resShort {1 ? ? ? ? ?} |
| 97 |
set resLong {1 2 3 4 5 6} |
| 98 |
} |
| 99 |
|
| 100 |
4 {set end { |
| 101 |
GET a |
| 102 |
GET b |
| 103 |
GET c |
| 104 |
GET a |
| 105 |
POST b address=home code=brief paid=yes |
| 106 |
GET c |
| 107 |
GET a |
| 108 |
GET b |
| 109 |
GET c |
| 110 |
STOP |
| 111 |
} |
| 112 |
set resShort {1 ? ? ? 5 ? ? ? ?} |
| 113 |
set resLong {1 2 3 4 5 6 7 8 9} |
| 114 |
} |
| 115 |
|
| 116 |
5 {set end { |
| 117 |
POST a address=home code=brief paid=yes |
| 118 |
POST b address=home code=brief paid=yes |
| 119 |
POST c address=home code=brief paid=yes |
| 120 |
POST a address=home code=brief paid=yes |
| 121 |
POST b address=home code=brief paid=yes |
| 122 |
POST c address=home code=brief paid=yes |
| 123 |
POST a address=home code=brief paid=yes |
| 124 |
POST b address=home code=brief paid=yes |
| 125 |
POST c address=home code=brief paid=yes |
| 126 |
STOP |
| 127 |
} |
| 128 |
set resShort {1 2 3 4 5 6 7 8 9} |
| 129 |
set resLong {1 2 3 4 5 6 7 8 9} |
| 130 |
} |
| 131 |
|
| 132 |
6 {set end { |
| 133 |
POST a address=home code=brief paid=yes |
| 134 |
GET b address=home code=brief paid=yes |
| 135 |
POST c address=home code=brief paid=yes |
| 136 |
GET a address=home code=brief paid=yes |
| 137 |
GET b address=home code=brief paid=yes |
| 138 |
POST c address=home code=brief paid=yes |
| 139 |
POST a address=home code=brief paid=yes |
| 140 |
HEAD b address=home code=brief paid=yes |
| 141 |
GET c address=home code=brief paid=yes |
| 142 |
STOP |
| 143 |
} |
| 144 |
set resShort {1 ? 3 ? ? 6 7 ? ?} |
| 145 |
set resLong {1 2 3 4 5 6 7 8 9} |
| 146 |
} |
| 147 |
|
| 148 |
7 {set end { |
| 149 |
GET b address=home code=brief paid=yes |
| 150 |
POST a address=home code=brief paid=yes |
| 151 |
GET a address=home code=brief paid=yes |
| 152 |
POST c address=home code=brief paid=yes |
| 153 |
GET b address=home code=brief paid=yes |
| 154 |
HEAD b address=home code=brief paid=yes |
| 155 |
POST c address=home code=brief paid=yes |
| 156 |
POST a address=home code=brief paid=yes |
| 157 |
GET c address=home code=brief paid=yes |
| 158 |
STOP |
| 159 |
} |
| 160 |
set resShort {1 2 ? 4 ? ? 7 8 ?} |
| 161 |
set resLong {1 2 3 4 5 6 7 8 9} |
| 162 |
} |
| 163 |
|
| 164 |
8 {set end { |
| 165 |
# Telling the server to close the connection. |
| 166 |
GET a |
| 167 |
GET b close=y |
| 168 |
GET c |
| 169 |
GET a |
| 170 |
GET b |
| 171 |
GET c |
| 172 |
GET a |
| 173 |
GET b |
| 174 |
GET c |
| 175 |
STOP |
| 176 |
} |
| 177 |
set resShort {1 ? 3 ? ? ? ? ? ?} |
| 178 |
set resLong {1 2 3 4 5 6 7 8 9} |
| 179 |
} |
| 180 |
|
| 181 |
9 {set end { |
| 182 |
# Telling the server to close the connection. |
| 183 |
GET a |
| 184 |
POST b close=y address=home code=brief paid=yes |
| 185 |
GET c |
| 186 |
GET a |
| 187 |
GET b |
| 188 |
GET c |
| 189 |
GET a |
| 190 |
GET b |
| 191 |
GET c |
| 192 |
STOP |
| 193 |
} |
| 194 |
set resShort {1 2 3 ? ? ? ? ? ?} |
| 195 |
set resLong {1 2 3 4 5 6 7 8 9} |
| 196 |
} |
| 197 |
|
| 198 |
10 {set end { |
| 199 |
# Telling the server to close the connection. |
| 200 |
GET a |
| 201 |
GET b close=y |
| 202 |
POST c address=home code=brief paid=yes |
| 203 |
GET a |
| 204 |
GET b |
| 205 |
GET c |
| 206 |
GET a |
| 207 |
GET b |
| 208 |
GET c |
| 209 |
STOP |
| 210 |
} |
| 211 |
set resShort {1 ? 3 ? ? ? ? ? ?} |
| 212 |
set resLong {1 2 3 4 5 6 7 8 9} |
| 213 |
} |
| 214 |
|
| 215 |
11 {set end { |
| 216 |
# Telling the server to close the connection twice. |
| 217 |
GET a |
| 218 |
GET b close=y |
| 219 |
GET c |
| 220 |
GET a |
| 221 |
GET b close=y |
| 222 |
GET c |
| 223 |
GET a |
| 224 |
GET b |
| 225 |
GET c |
| 226 |
STOP |
| 227 |
} |
| 228 |
set resShort {1 ? 3 ? ? 6 ? ? ?} |
| 229 |
set resLong {1 2 3 4 5 6 7 8 9} |
| 230 |
} |
| 231 |
|
| 232 |
12 {set end { |
| 233 |
# Telling the server to delay before sending the response. |
| 234 |
GET a |
| 235 |
GET b delay=1 |
| 236 |
GET c |
| 237 |
GET a |
| 238 |
GET b |
| 239 |
STOP |
| 240 |
} |
| 241 |
set resShort {1 ? ? ? ?} |
| 242 |
set resLong {1 2 3 4 5} |
| 243 |
} |
| 244 |
|
| 245 |
13 {set end { |
| 246 |
# Making the server close the connection (time out). |
| 247 |
GET a |
| 248 |
WAIT 2000 |
| 249 |
GET b |
| 250 |
GET c |
| 251 |
GET a |
| 252 |
GET b |
| 253 |
STOP |
| 254 |
} |
| 255 |
set resShort {1 2 ? ? ?} |
| 256 |
set resLong {1 2 3 4 5} |
| 257 |
} |
| 258 |
|
| 259 |
14 {set end { |
| 260 |
# Making the server close the connection (time out) twice. |
| 261 |
GET a |
| 262 |
WAIT 2000 |
| 263 |
GET b |
| 264 |
GET c |
| 265 |
GET a |
| 266 |
WAIT 2000 |
| 267 |
GET b |
| 268 |
GET c |
| 269 |
GET a |
| 270 |
GET b |
| 271 |
GET c |
| 272 |
STOP |
| 273 |
} |
| 274 |
set resShort {1 2 ? ? 5 ? ? ? ?} |
| 275 |
set resLong {1 2 3 4 5 6 7 8 9} |
| 276 |
} |
| 277 |
|
| 278 |
15 {set end { |
| 279 |
POST a address=home code=brief paid=yes |
| 280 |
POST b address=home code=brief paid=yes close=y delay=1 |
| 281 |
POST c address=home code=brief paid=yes delay=1 |
| 282 |
POST a address=home code=brief paid=yes close=y |
| 283 |
WAIT 2000 |
| 284 |
POST b address=home code=brief paid=yes delay=1 |
| 285 |
POST c address=home code=brief paid=yes close=y |
| 286 |
POST a address=home code=brief paid=yes |
| 287 |
POST b address=home code=brief paid=yes close=y |
| 288 |
POST c address=home code=brief paid=yes |
| 289 |
STOP |
| 290 |
} |
| 291 |
set resShort {1 2 3 4 5 6 7 8 9} |
| 292 |
set resLong {1 2 3 4 5 6 7 8 9} |
| 293 |
} |
| 294 |
|
| 295 |
16 {set end { |
| 296 |
POST a address=home code=brief paid=yes |
| 297 |
GET b address=home code=brief paid=yes |
| 298 |
POST c address=home code=brief paid=yes close=y |
| 299 |
GET a address=home code=brief paid=yes |
| 300 |
GET b address=home code=brief paid=yes close=y |
| 301 |
POST c address=home code=brief paid=yes |
| 302 |
WAIT 2000 |
| 303 |
POST a address=home code=brief paid=yes |
| 304 |
HEAD b address=home code=brief paid=yes close=y |
| 305 |
GET c address=home code=brief paid=yes |
| 306 |
STOP |
| 307 |
} |
| 308 |
set resShort {1 ? 3 4 ? 6 7 ? 9} |
| 309 |
set resLong {1 2 3 4 5 6 7 8 9} |
| 310 |
} |
| 311 |
|
| 312 |
17 {set end { |
| 313 |
GET b address=home code=brief paid=yes |
| 314 |
POST a address=home code=brief paid=yes |
| 315 |
GET a address=home code=brief paid=yes |
| 316 |
POST c address=home code=brief paid=yes close=y |
| 317 |
GET b address=home code=brief paid=yes |
| 318 |
HEAD b address=home code=brief paid=yes close=y |
| 319 |
POST c address=home code=brief paid=yes |
| 320 |
WAIT 2000 |
| 321 |
POST a address=home code=brief paid=yes |
| 322 |
WAIT 2000 |
| 323 |
GET c address=home code=brief paid=yes |
| 324 |
STOP |
| 325 |
} |
| 326 |
set resShort {1 2 3 4 5 ? 7 8 9} |
| 327 |
set resLong {1 2 3 4 5 6 7 8 9} |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
18 {set end { |
| 332 |
REPOST 0 |
| 333 |
GET a |
| 334 |
WAIT 2000 |
| 335 |
POST b address=home code=brief paid=yes |
| 336 |
GET c |
| 337 |
GET a |
| 338 |
STOP |
| 339 |
} |
| 340 |
set resShort {1 2 ? ?} |
| 341 |
set resLong {1 2 3 4} |
| 342 |
# resShort is overwritten below for the case ($te == 1). |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
19 {set end { |
| 347 |
REPOST 0 |
| 348 |
GET a |
| 349 |
WAIT 2000 |
| 350 |
GET b address=home code=brief paid=yes |
| 351 |
GET c |
| 352 |
GET a |
| 353 |
STOP |
| 354 |
} |
| 355 |
set resShort {1 2 ? ?} |
| 356 |
set resLong {1 2 3 4} |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
20 {set end { |
| 361 |
POSTFRESH 1 |
| 362 |
GET a |
| 363 |
WAIT 2000 |
| 364 |
POST b address=home code=brief paid=yes |
| 365 |
GET c |
| 366 |
GET a |
| 367 |
STOP |
| 368 |
} |
| 369 |
set resShort {1 3 ?} |
| 370 |
set resLong {1 3 4} |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
21 {set end { |
| 375 |
POSTFRESH 1 |
| 376 |
GET a |
| 377 |
WAIT 2000 |
| 378 |
GET b address=home code=brief paid=yes |
| 379 |
GET c |
| 380 |
GET a |
| 381 |
STOP |
| 382 |
} |
| 383 |
set resShort {1 2 ? ?} |
| 384 |
set resLong {1 2 3 4} |
| 385 |
} |
| 386 |
|
| 387 |
22 {set end { |
| 388 |
GET a |
| 389 |
WAIT 2000 |
| 390 |
KEEPALIVE 0 |
| 391 |
POST b address=home code=brief paid=yes |
| 392 |
KEEPALIVE 1 |
| 393 |
GET c |
| 394 |
GET a |
| 395 |
STOP |
| 396 |
} |
| 397 |
set resShort {1 3 ?} |
| 398 |
set resLong {1 3 4} |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
23 {set end { |
| 403 |
GET a |
| 404 |
WAIT 2000 |
| 405 |
KEEPALIVE 0 |
| 406 |
GET b address=home code=brief paid=yes |
| 407 |
KEEPALIVE 1 |
| 408 |
GET c |
| 409 |
GET a |
| 410 |
STOP |
| 411 |
} |
| 412 |
set resShort {1 3 ?} |
| 413 |
set resLong {1 3 4} |
| 414 |
} |
| 415 |
|
| 416 |
24 {set end { |
| 417 |
GET a |
| 418 |
KEEPALIVE 0 |
| 419 |
POST b address=home code=brief paid=yes |
| 420 |
KEEPALIVE 1 |
| 421 |
GET c |
| 422 |
GET a |
| 423 |
STOP |
| 424 |
} |
| 425 |
set resShort {1 ? ?} |
| 426 |
set resLong {1 3 4} |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
25 {set end { |
| 431 |
GET a |
| 432 |
KEEPALIVE 0 |
| 433 |
GET b address=home code=brief paid=yes |
| 434 |
KEEPALIVE 1 |
| 435 |
GET c |
| 436 |
GET a |
| 437 |
STOP |
| 438 |
} |
| 439 |
set resShort {1 ? ?} |
| 440 |
set resLong {1 3 4} |
| 441 |
} |
| 442 |
|
| 443 |
default { |
| 444 |
return -code error {no matching script} |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
if {$ca < 3} { |
| 450 |
# Not Keep-Alive. |
| 451 |
set result "Passed all sanity checks." |
| 452 |
|
| 453 |
} elseif {$ca == 3} { |
| 454 |
# Keep-Alive, not pipelined. |
| 455 |
set result {} |
| 456 |
append result "Passed all sanity checks.\n" |
| 457 |
append result "Have overlaps including response body:\n" |
| 458 |
|
| 459 |
} else { |
| 460 |
# Keep-Alive, pipelined: ($ca == 4) |
| 461 |
set result {} |
| 462 |
append result "Passed all sanity checks.\n" |
| 463 |
append result "Overlap-free without response body:\n" |
| 464 |
append result "$resShort" |
| 465 |
} |
| 466 |
|
| 467 |
# - The special case of test *.18*-testEof needs test results to be |
| 468 |
# individually written. |
| 469 |
# - These test -repost 0 when there is a POST to apply it to, and the server |
| 470 |
# timeout has not been detected. |
| 471 |
if {($cb == 18) && ($te == 1)} { |
| 472 |
if {$ca < 3} { |
| 473 |
# Not Keep-Alive. |
| 474 |
set result "Passed all sanity checks." |
| 475 |
|
| 476 |
} elseif {$ca == 3 && $delay == 0} { |
| 477 |
# Keep-Alive, not pipelined. |
| 478 |
set result [MakeMessage { |
| 479 |
|Problems with sanity checks: |
| 480 |
|Wrong sequence for token ::http::2 - {A B C D X X X} |
| 481 |
|- and error(s) X |
| 482 |
|Wrong sequence for token ::http::3 - {A X X} |
| 483 |
|- and error(s) X |
| 484 |
|Wrong sequence for token ::http::4 - {A X X X} |
| 485 |
|- and error(s) X |
| 486 |
| |
| 487 |
|Have overlaps including response body: |
| 488 |
| |
| 489 |
}] |
| 490 |
|
| 491 |
} elseif {$ca == 3} { |
| 492 |
# Keep-Alive, not pipelined. |
| 493 |
set result [MakeMessage { |
| 494 |
|Problems with sanity checks: |
| 495 |
|Wrong sequence for token ::http::2 - {A B C D X X X} |
| 496 |
|- and error(s) X |
| 497 |
| |
| 498 |
|Have overlaps including response body: |
| 499 |
| |
| 500 |
}] |
| 501 |
|
| 502 |
} elseif {$delay == 0} { |
| 503 |
# Keep-Alive, pipelined: ($ca == 4) |
| 504 |
set result [MakeMessage { |
| 505 |
|Problems with sanity checks: |
| 506 |
|Wrong sequence for token ::http::2 - {A B C D X X X} |
| 507 |
|- and error(s) X |
| 508 |
|Wrong sequence for token ::http::3 - {A X X} |
| 509 |
|- and error(s) X |
| 510 |
|Wrong sequence for token ::http::4 - {A X X X} |
| 511 |
|- and error(s) X |
| 512 |
| |
| 513 |
|Overlap-free without response body: |
| 514 |
| |
| 515 |
}] |
| 516 |
|
| 517 |
} else { |
| 518 |
set result [MakeMessage { |
| 519 |
|Problems with sanity checks: |
| 520 |
|Wrong sequence for token ::http::2 - {A B C D X X X} |
| 521 |
|- and error(s) X |
| 522 |
| |
| 523 |
|Overlap-free without response body: |
| 524 |
| |
| 525 |
}] |
| 526 |
|
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
return [list "$start$middle$end" $result] |
| 531 |
} |
| 532 |
|
| 533 |
# ------------------------------------------------------------------------------ |
| 534 |
# Proc MakeMessage |
| 535 |
# ------------------------------------------------------------------------------ |
| 536 |
# WHD's one-line command to generate multi-line strings from readable code. |
| 537 |
# |
| 538 |
# Example: |
| 539 |
# set blurb [MakeMessage { |
| 540 |
# |This command allows multi-line strings to be created with readable |
| 541 |
# |code, and without breaking the rules for indentation. |
| 542 |
# | |
| 543 |
# |The command shifts the entire block of text to the left, omitting |
| 544 |
# |the pipe character and the spaces to its left. |
| 545 |
# }] |
| 546 |
# ------------------------------------------------------------------------------ |
| 547 |
|
| 548 |
proc MakeMessage {in} { |
| 549 |
regsub -all -line {^\s*\|} [string trim $in] {} |
| 550 |
# N.B. Implicit Return. |
| 551 |
} |
| 552 |
|
| 553 |
|
| 554 |
proc ReturnTestScript {ca cb delay te} { |
| 555 |
lassign [ReturnTestScriptAndResult $ca $cb $delay $te] script result |
| 556 |
return $script |
| 557 |
} |
| 558 |
|
| 559 |
proc ReturnTestResult {ca cb delay te} { |
| 560 |
lassign [ReturnTestScriptAndResult $ca $cb $delay $te] script result |
| 561 |
return $result |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
# ------------------------------------------------------------------------------ |
| 566 |
# (2) Command to run a test script and use httpTest to analyse the logs. |
| 567 |
# ------------------------------------------------------------------------------ |
| 568 |
|
| 569 |
namespace import httpTestScript::runHttpTestScript |
| 570 |
namespace import httpTestScript::cleanupHttpTestScript |
| 571 |
namespace import httpTest::cleanupHttpTest |
| 572 |
namespace import httpTest::logAnalyse |
| 573 |
namespace import httpTest::setHttpTestOptions |
| 574 |
|
| 575 |
proc RunTest {header footer delay te} { |
| 576 |
set num [runHttpTestScript [ReturnTestScript $header $footer $delay $te]] |
| 577 |
set skipOverlaps 0 |
| 578 |
set notPiped {} |
| 579 |
set notIncluded {} |
| 580 |
|
| 581 |
# -------------------------------------------------------------------------- |
| 582 |
# Custom code for specific tests |
| 583 |
# -------------------------------------------------------------------------- |
| 584 |
if {$header < 3} { |
| 585 |
set skipOverlaps 1 |
| 586 |
for {set i 1} {$i <= $num} {incr i} { |
| 587 |
lappend notPiped $i |
| 588 |
} |
| 589 |
} elseif {$header > 2 && $footer == 18 && $te == 1} { |
| 590 |
set skipOverlaps 1 |
| 591 |
if {$delay == 0} { |
| 592 |
# Transaction 1 is conventional. |
| 593 |
# Check that transactions 2,3,4 are cancelled. |
| 594 |
set notPiped {1} |
| 595 |
set notIncluded $notPiped |
| 596 |
} else { |
| 597 |
# Transaction 1 is conventional. |
| 598 |
# Check that transaction 2 is cancelled. |
| 599 |
# The timing of transactions 3 and 4 is uncertain. |
| 600 |
set notPiped {1 3 4} |
| 601 |
set notIncluded $notPiped |
| 602 |
} |
| 603 |
} elseif {$footer in {20 22 23 24 25}} { |
| 604 |
# Transaction 2 uses its own socket. |
| 605 |
set notPiped 2 |
| 606 |
set notIncluded $notPiped |
| 607 |
} else { |
| 608 |
} |
| 609 |
# -------------------------------------------------------------------------- |
| 610 |
# End of custom code for specific tests |
| 611 |
# -------------------------------------------------------------------------- |
| 612 |
|
| 613 |
|
| 614 |
set Results [logAnalyse $num $skipOverlaps $notIncluded $notPiped] |
| 615 |
lassign $Results msg cleanE cleanF dirtyE dirtyF |
| 616 |
if {$msg eq {}} { |
| 617 |
set msg "Passed all sanity checks." |
| 618 |
} else { |
| 619 |
set msg "Problems with sanity checks:\n$msg" |
| 620 |
} |
| 621 |
|
| 622 |
if 0 { |
| 623 |
puts $msg |
| 624 |
puts "Overlap-free including response body:\n$cleanF" |
| 625 |
puts "Have overlaps including response body:\n$dirtyF" |
| 626 |
puts "Overlap-free without response body:\n$cleanE" |
| 627 |
puts "Have overlaps without response body:\n$dirtyE" |
| 628 |
} |
| 629 |
|
| 630 |
if {$header < 3} { |
| 631 |
# No ordering, just check that transactions all finish |
| 632 |
set result $msg |
| 633 |
} elseif {$header == 3} { |
| 634 |
# Not pipelined - check overlaps with response body. |
| 635 |
set result "$msg\nHave overlaps including response body:\n$dirtyF" |
| 636 |
} else { |
| 637 |
# Pipelined - check overlaps without response body. Check that the |
| 638 |
# first request, the first requests after replay, and POSTs are clean. |
| 639 |
set result "$msg\nOverlap-free without response body:\n$cleanE" |
| 640 |
} |
| 641 |
set ::nTokens $num |
| 642 |
return $result |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
# ------------------------------------------------------------------------------ |
| 647 |
# (3) VERBOSITY CONTROL |
| 648 |
# ------------------------------------------------------------------------------ |
| 649 |
# If tests fail, run an individual test with -verbose 1 or 2 for diagnosis. |
| 650 |
# If still obscure, uncomment #Log and ##Log lines in the http package. |
| 651 |
# ------------------------------------------------------------------------------ |
| 652 |
|
| 653 |
setHttpTestOptions -verbose 0 |
| 654 |
|
| 655 |
# ------------------------------------------------------------------------------ |
| 656 |
# (4) Define the base URLs used for testing. Each must have a query string. |
| 657 |
# ------------------------------------------------------------------------------ |
| 658 |
# - A HTTP/1.1 server is required. It should be configured to provide |
| 659 |
# persistent connections when requested to do so, and to close these |
| 660 |
# connections if they are idle for one second. |
| 661 |
# - The resource must be served with status 200 in response to a valid GET or |
| 662 |
# POST. |
| 663 |
# - The value of "page" is always specified in the query-string. Different |
| 664 |
# resources for the three values of "page" allow testing of both chunked and |
| 665 |
# unchunked transfer encoding. |
| 666 |
# - The variables "close" and "delay" may be specified in the query-string (for |
| 667 |
# a GET) or the request body (for a POST). |
| 668 |
# - "delay" is a numerical value in seconds, and causes the server to delay |
| 669 |
# the response, including headers. |
| 670 |
# - "close", if it has the value "y", instructs the server to close the |
| 671 |
# connection ater the current request. |
| 672 |
# - Any other variables should be ignored. |
| 673 |
# ------------------------------------------------------------------------------ |
| 674 |
|
| 675 |
namespace eval ::httpTestScript { |
| 676 |
variable URL |
| 677 |
array set URL { |
| 678 |
a http://test-tcl-http.kerlin.org/index.html?page=privacy |
| 679 |
b http://test-tcl-http.kerlin.org/index.html?page=conditions |
| 680 |
c http://test-tcl-http.kerlin.org/index.html?page=welcome |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
|
| 685 |
# ------------------------------------------------------------------------------ |
| 686 |
# (5) Define the tests |
| 687 |
# ------------------------------------------------------------------------------ |
| 688 |
# Constraints: |
| 689 |
# - serverNeeded - the URLs defined at (4) must be available, and must have the |
| 690 |
# properties specified there. |
| 691 |
# - duplicate - the value of -pipeline does not matter if -keepalive 0 |
| 692 |
# - timeout1s - tests that work correctly only if the server closes |
| 693 |
# persistent connections after one second. |
| 694 |
# |
| 695 |
# Server timeout of persistent connections should be 1s. Delays of 2s are |
| 696 |
# intended to cause timeout. |
| 697 |
# Servers are usually configured to use a longer timeout: this will cause the |
| 698 |
# tests to fail. The "2000" could be replaced with a larger number, but the |
| 699 |
# tests will then be inconveniently slow. |
| 700 |
# ------------------------------------------------------------------------------ |
| 701 |
|
| 702 |
#testConstraint serverNeeded 1 |
| 703 |
#testConstraint timeout1s 1 |
| 704 |
#testConstraint duplicate 1 |
| 705 |
|
| 706 |
# ------------------------------------------------------------------------------ |
| 707 |
# Proc SetTestEof - to edit the command ::http::KeepSocket |
| 708 |
# ------------------------------------------------------------------------------ |
| 709 |
# The usual line in command ::http::KeepSocket is " set TEST_EOF 0". |
| 710 |
# Whether the value set in the file is 0 or 1, change it here to the value |
| 711 |
# specified by the argument. |
| 712 |
# |
| 713 |
# It is worth doing all tests for both values of the argument. |
| 714 |
# |
| 715 |
# test 0 - ::http::KeepSocket is unchanged, detects server eof where possible |
| 716 |
# and closes the connection. |
| 717 |
# test 1 - ::http::KeepSocket is edited, does not detect server eof, so the |
| 718 |
# reaction to finding server eof can be tested without the difficulty |
| 719 |
# of testing in the few milliseconds of an asynchronous close event. |
| 720 |
# ------------------------------------------------------------------------------ |
| 721 |
|
| 722 |
proc SetTestEof {test} { |
| 723 |
set body [info body ::http::KeepSocket] |
| 724 |
set subs " set TEST_EOF $test" |
| 725 |
set count [regsub -line -all -- {^\s*set TEST_EOF .*$} $body $subs newBody] |
| 726 |
if {$count != 1} { |
| 727 |
return -code error {proc ::http::KeepSocket has unexpected form} |
| 728 |
} |
| 729 |
proc ::http::KeepSocket {token} $newBody |
| 730 |
return |
| 731 |
} |
| 732 |
|
| 733 |
for {set header 1} {$header <= 4} {incr header} { |
| 734 |
if {$header == 4} { |
| 735 |
setHttpTestOptions -dotted 1 |
| 736 |
set match glob |
| 737 |
} else { |
| 738 |
setHttpTestOptions -dotted 0 |
| 739 |
set match exact |
| 740 |
} |
| 741 |
|
| 742 |
if {$header == 2} { |
| 743 |
set cons0 {serverNeeded duplicate} |
| 744 |
} else { |
| 745 |
set cons0 serverNeeded |
| 746 |
} |
| 747 |
|
| 748 |
for {set footer 1} {$footer <= 25} {incr footer} { |
| 749 |
foreach {delay label} { |
| 750 |
0 a |
| 751 |
1 b |
| 752 |
2 c |
| 753 |
3 d |
| 754 |
5 e |
| 755 |
8 f |
| 756 |
12 g |
| 757 |
100 h |
| 758 |
500 i |
| 759 |
2000 j |
| 760 |
} { |
| 761 |
foreach te {0 1} { |
| 762 |
if {$te} { |
| 763 |
set tag testEof |
| 764 |
} else { |
| 765 |
set tag normal |
| 766 |
} |
| 767 |
set suffix {} |
| 768 |
set cons $cons0 |
| 769 |
|
| 770 |
# ------------------------------------------------------------------ |
| 771 |
# Custom code for individual tests |
| 772 |
# ------------------------------------------------------------------ |
| 773 |
if {$footer in {18}} { |
| 774 |
# Custom code: |
| 775 |
if {($label eq "j") && ($te == 1)} { |
| 776 |
continue |
| 777 |
} |
| 778 |
if {$te == 1} { |
| 779 |
# The test (of REPOST 0) is useful if tag is "testEof" |
| 780 |
# (server timeout without client reaction). The same test |
| 781 |
# has a different result if tag is "normal". |
| 782 |
|
| 783 |
set suffix " - extra test for -repost 0 - ::http::2 must be" |
| 784 |
append suffix " cancelled" |
| 785 |
if {($delay == 0)} { |
| 786 |
append suffix ", along with ::http::3 ::http::4 if" |
| 787 |
append suffix " the test creates these before ::http::2" |
| 788 |
append suffix " is cancelled" |
| 789 |
} |
| 790 |
} else { |
| 791 |
} |
| 792 |
} elseif {$footer in {19}} { |
| 793 |
set suffix " - extra test for -repost 0" |
| 794 |
} elseif {$footer in {20 21}} { |
| 795 |
set suffix " - extra test for -postfresh 1" |
| 796 |
if {($footer == 20)} { |
| 797 |
append suffix " - ::http::2 uses a separate socket" |
| 798 |
append suffix ", other requests use a persistent connection" |
| 799 |
} |
| 800 |
} elseif {$footer in {22 23 24 25}} { |
| 801 |
append suffix " - ::http::2 uses a separate socket" |
| 802 |
append suffix ", other requests use a persistent connection" |
| 803 |
} else { |
| 804 |
} |
| 805 |
|
| 806 |
if {($footer >= 13 && $footer <= 23)} { |
| 807 |
# Test use WAIT and depend on server timeout before this time. |
| 808 |
lappend cons timeout1s |
| 809 |
} |
| 810 |
# ------------------------------------------------------------------ |
| 811 |
# End of custom code. |
| 812 |
# ------------------------------------------------------------------ |
| 813 |
|
| 814 |
set name "pipeline test header $header footer $footer delay $delay $tag$suffix" |
| 815 |
|
| 816 |
|
| 817 |
# Here's the test: |
| 818 |
test httpPipeline-${header}.${footer}${label}-${tag} $name \ |
| 819 |
-constraints $cons \ |
| 820 |
-setup [string map [list TE $te] { |
| 821 |
# Restore default values for tests: |
| 822 |
http::config -pipeline 1 -postfresh 0 -repost 1 |
| 823 |
http::init |
| 824 |
set http::http(uid) 0 |
| 825 |
SetTestEof {TE} |
| 826 |
}] -body [list RunTest $header $footer $delay $te] -cleanup { |
| 827 |
# Restore default values for tests: |
| 828 |
http::config -pipeline 1 -postfresh 0 -repost 1 |
| 829 |
cleanupHttpTestScript |
| 830 |
SetTestEof 0 |
| 831 |
cleanupHttpTest |
| 832 |
after 2000 |
| 833 |
# Wait for persistent sockets on the server to time out. |
| 834 |
} -result [ReturnTestResult $header $footer $delay $te] -match $match |
| 835 |
|
| 836 |
|
| 837 |
} |
| 838 |
|
| 839 |
} |
| 840 |
} |
| 841 |
} |
| 842 |
|
| 843 |
# ------------------------------------------------------------------------------ |
| 844 |
# (*) Notes on tests *.18*-testEof, *.19*-testEof - these test -repost 0 |
| 845 |
# ------------------------------------------------------------------------------ |
| 846 |
# These tests are a bit awkward because the main test kit analyses whether all |
| 847 |
# requests are satisfied, with retries if necessary, and it has result analysis |
| 848 |
# for processing retry logs. |
| 849 |
# - *.18*-testEof tests that certain requests are NOT satisfied, so the analysis |
| 850 |
# is a one-off. |
| 851 |
# - Tests *.18a-testEof depend on client/server timing - the test needs to call |
| 852 |
# http::geturl for all requests before the POST (request 2) is cancelled. |
| 853 |
# We test that requests 2, 3, 4 are all cancelled. |
| 854 |
# - Other tests *.18*-testEof may not request 3 and 4 in time for the to be |
| 855 |
# added to the write queue before request 2 is completed. We simply check that |
| 856 |
# request 2 is cancelled. |
| 857 |
# - The behaviour is different if all connections are allowed to time out |
| 858 |
# (label "j"). This case is not needed to test -repost 0, and is omitted. |
| 859 |
# - Tests *.18*-normal and *.19* are conventional (-repost 0 should have no |
| 860 |
# effect). |
| 861 |
# ------------------------------------------------------------------------------ |
| 862 |
|
| 863 |
|
| 864 |
unset header footer delay label suffix match cons name te |
| 865 |
namespace delete ::httpTest |
| 866 |
namespace delete ::httpTestScript |
| 867 |
|
| 868 |
::tcltest::cleanupTests |