|
| 1 | +# CDN Tests |
| 2 | + |
| 3 | +These tests cover HTTP-specified behaviours for CDNs, primarily from |
| 4 | +[RFC7234](http://httpwg.org/specs/rfc7234.html), but as seen through the lens of |
| 5 | +[Fetch](https://fetch.spec.whatwg.org/). |
| 6 | + |
| 7 | +A few notes: |
| 8 | + |
| 9 | +* By its nature, caching is optional; some tests expecting a response to be cached might fail |
| 10 | + because the client chose not to cache it, or chose to race the cache with a network request. |
| 11 | + |
| 12 | +* Likewise, some tests might fail because there is a separate document-level cache that's |
| 13 | + ill-defined; see [this issue](https://github.com/whatwg/fetch/issues/354). |
| 14 | + |
| 15 | +* Some browser caches will behave differently when reloading / shift-reloading, despite the `cache |
| 16 | + mode` staying the same. |
| 17 | + |
| 18 | +* They only work reliably on Chrome for the time being; see [this bug](https://github.com/whatwg/fetch/issues/722). |
| 19 | + |
| 20 | +## Running the Tests |
| 21 | + |
| 22 | +First, start the server-side: |
| 23 | + |
| 24 | +> node server.js |
| 25 | +
|
| 26 | +Then, configure your CDN to use port `8000` on that hostname as the origin. Point a browser (as above, currently Chrome) to the CDN. |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +## Test Format |
| 31 | + |
| 32 | +Each test run gets its own URL, randomized content, and operates independently. |
| 33 | + |
| 34 | +Tests are kept in JavaScript files in `tests/`, each file representing a suite. |
| 35 | + |
| 36 | +A suite is an object with a `name` member and a `tests` member; e.g., |
| 37 | + |
| 38 | +```javascript |
| 39 | +export default { |
| 40 | + name: 'Example Tests', |
| 41 | + tests: [ ... ] |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +The `tests` member is an array of objects, with the following members: |
| 46 | + |
| 47 | +- `name` - The name of the test. |
| 48 | +- `requests` - a list of request objects (see below). |
| 49 | +- `browser_only` - if `true`, will not run on non-browser caches. |
| 50 | +- `browser_skip` - if `true, will not run on browser caches. |
| 51 | + |
| 52 | +Possible members of a request object: |
| 53 | + |
| 54 | +- `template` - A template object for the request, by name -- see `templates.js`. |
| 55 | +- `request_method` - A string containing the HTTP method to be used. |
| 56 | +- `request_headers` - An array of `[header_name_string, header_value_string]` arrays to |
| 57 | + emit in the request. |
| 58 | +- `request_body` - A string to use as the request body. |
| 59 | +- `query_arg` - query arguments to add. |
| 60 | +- `filename` - filename to use. |
| 61 | +- `mode` - The mode string to pass to `fetch()`. |
| 62 | +- `credentials` - The credentials string to pass to `fetch()`. |
| 63 | +- `cache` - The cache string to pass to `fetch()`. |
| 64 | +- `pause_after` - Boolean controlling a 3-second pause after the request completes. |
| 65 | +- `response_status` - A `[number, string]` array containing the HTTP status code |
| 66 | + and phrase to return. |
| 67 | +- `response_headers` - An array of `[header_name_string, header_value_string]` arrays to |
| 68 | + emit in the response. These values will also be checked like |
| 69 | + expected_response_headers, unless there is a third value that is |
| 70 | + `false`. |
| 71 | +- `response_body` - String to send as the response body. If not set, it will contain |
| 72 | + the test identifier. |
| 73 | +- `expected_type` - One of `["cached", "not_cached", "lm_validate", "etag_validate", "error"]` |
| 74 | +- `expected_status` - A number representing a HTTP status code to check the response for. |
| 75 | + If not set, the value of `response_status[0]` will be used; if that |
| 76 | + is not set, 200 will be used. |
| 77 | +- `expected_request_headers` - An array of `[header_name_string, header_value_string]` representing |
| 78 | + headers to check the request for. |
| 79 | +- `expected_response_headers` - An array of `[header_name_string, header_value_string]` representing |
| 80 | + headers to check the response for. See also response_headers. |
| 81 | +- `expected_response_text` - A string to check the response body against. |
| 82 | + |
| 83 | +`server.js` stashes an entry containing observed headers for each request it receives. When the |
| 84 | +test fetches have run, this state is retrieved and the expected_* lists are checked, including |
| 85 | +their length. |
| 86 | + |
0 commit comments