-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwp.js
57 lines (44 loc) · 1.57 KB
/
wp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import http from 'k6/http'
import { Rate } from 'k6/metrics'
import Metrics from './lib/metrics.js'
import { sample, validateSiteUrl, validateSitemapUrl, wpSitemap, responseWasCached, bypassPageCacheCookies } from './lib/helpers.js'
export const options = {
vus: 20,
duration: '20s',
summaryTimeUnit: 'ms',
ext: {
loadimpact: {
name: 'Random WordPress requests',
note: 'Fetch all WordPress sitemaps and request random URLs.',
projectID: __ENV.PROJECT_ID || null
},
},
}
const errorRate = new Rate('errors')
const responseCacheRate = new Rate('response_cached')
// These metrics are provided by Object Cache Pro when `analytics.footnote` is enabled
const metrics = new Metrics()
export function setup () {
const siteUrl = __ENV.SITE_URL
validateSiteUrl(siteUrl)
const sitemapUrl = __ENV.SITEMAP_URL || `${siteUrl}/wp-sitemap.xml`
validateSitemapUrl(sitemapUrl)
return {
startedAt: Date.now(),
urls: wpSitemap(sitemapUrl).urls,
}
}
export function teardown (data) {
const startedAt = new Date(data.startedAt)
const endedAt = new Date()
console.info(`Run started at ${startedAt.toJSON()}`)
console.info(`Run ended at ${endedAt.toJSON()}`)
}
export default function (data) {
let cookies = __ENV.BYPASS_CACHE ? bypassPageCacheCookies() : {}
const url = sample(data.urls)
const response = http.get(url, { cookies })
errorRate.add(response.status >= 400)
responseCacheRate.add(responseWasCached(response))
metrics.addResponseMetrics(response)
}