MCPcopy
hub / github.com/nodejs/undici / runCacheTest

Function runCacheTest

test/issue-3959.js:10–54  ·  view source on GitHub ↗
(store)

Source from the content-addressed store, hash-verified

8
9describe('Cache with Vary headers', () => {
10 async function runCacheTest (store) {
11 let requestCount = 0
12 const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {
13 requestCount++
14 res.setHeader('Vary', 'Accept-Encoding')
15 res.setHeader('Cache-Control', 'max-age=60')
16 res.end(`Request count: ${requestCount}`)
17 })
18
19 await new Promise(resolve => server.listen(0, resolve))
20 const port = server.address().port
21 const url = `http://localhost:${port}`
22
23 const agent = new Agent()
24 setGlobalDispatcher(
25 agent.compose(
26 interceptors.cache({
27 store,
28 cacheByDefault: 1000,
29 methods: ['GET']
30 })
31 )
32 )
33
34 const res1 = await request(url)
35 const body1 = await res1.body.text()
36 assert.strictEqual(body1, 'Request count: 1')
37 assert.strictEqual(requestCount, 1)
38
39 const res2 = await request(url)
40 const body2 = await res2.body.text()
41 assert.strictEqual(body2, 'Request count: 1')
42 assert.strictEqual(requestCount, 1)
43
44 const res3 = await request(url, {
45 headers: {
46 'Accept-Encoding': 'gzip'
47 }
48 })
49 const body3 = await res3.body.text()
50 assert.strictEqual(body3, 'Request count: 2')
51 assert.strictEqual(requestCount, 2)
52
53 await new Promise(resolve => server.close(resolve))
54 }
55
56 test('should cache response with MemoryCacheStore when Vary header exists but request header is missing', async () => {
57 await runCacheTest(new MemoryCacheStore())

Callers 1

issue-3959.jsFile · 0.85

Calls 9

createServerFunction · 0.85
setGlobalDispatcherFunction · 0.85
listenMethod · 0.80
composeMethod · 0.80
cacheMethod · 0.80
requestFunction · 0.70
textMethod · 0.65
closeMethod · 0.65
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…