Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance testing framework #857

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions test/perf/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
const sleep = n => new Promise(resolve => setTimeout(resolve, n))

module.exports.landingPage = async function (user, options) {
const travelList = {
name: 'landingPageList',
SELECT: {
from: { ref: ['processor', 'Travel'] },
count: true,
columns: [
{ ref: ['BeginDate'] },
{ ref: ['Description'] },
{ ref: ['EndDate'] },
{ ref: ['HasActiveEntity'] },
{ ref: ['HasDraftEntity'] },
{ ref: ['IsActiveEntity'] },
{ ref: ['TotalPrice'] },
{ ref: ['TravelID'] },
{ ref: ['TravelUUID'] },
{
ref: ['DraftAdministrativeData'], expand: [
{ ref: ['DraftUUID'] },
{ ref: ['InProcessByUser'] },
{ ref: ['LastChangedByUser'] },
]
}, {
ref: ['TravelStatus'], expand: [
{ ref: ['code'] },
{ ref: ['name'] },
]
}, {
ref: ['to_Agency'], expand: [
{ ref: ['AgencyID'] },
{ ref: ['Name'] },
]
}, {
ref: ['to_Customer'], expand: [
{ ref: ['CustomerID'] },
{ ref: ['LastName'] },
]
},
],
orderBy: [
{ ref: ['TravelID'], sort: 'desc' }
],
where: [
{ ref: ['IsActiveEntity'] },
'=',
{ val: false },
'or',
{ ref: ['SiblingEntity', 'IsActiveEntity'] },
'=',
{ val: null }
],
limit: {
rows: { val: 30 },
offset: { val: 0 }
}
}
}

const agencyPopup = {
name: 'landingPageAgencyPopup',
SELECT: {
from: { ref: ['processor', 'TravelAgency'] },
count: true,
columns: [
{ ref: ['AgencyID'] },
{ ref: ['City'] },
{ ref: ['CountryCode_code'] },
{ ref: ['EMailAddress'] },
{ ref: ['Name'] },
{ ref: ['PhoneNumber'] },
{ ref: ['PostalCode'] },
{ ref: ['Street'] },
{ ref: ['WebAddress'] },
],
orderby: [
{ ref: ['AgencyID'] },
],
limit: {
rows: { val: 58 }
}
}
}

const customerPopup = {
name: 'landingPageCustomerPopup',
SELECT: {
from: { ref: ['processor', 'Passenger'] },
count: true,
columns: [
{ ref: ['City'] },
{ ref: ['CountryCode_code'] },
{ ref: ['CustomerID'] },
{ ref: ['EMailAddress'] },
{ ref: ['FirstName'] },
{ ref: ['LastName'] },
{ ref: ['PhoneNumber'] },
{ ref: ['PostalCode'] },
{ ref: ['Street'] },
{ ref: ['Title'] },
],
orderby: [
{ ref: ['CustomerID'] },
],
limit: {
rows: { val: 58 }
}
}
}

const travelStatusPopover = {
name: 'landingPageStatusPopover',
SELECT: {
from: { ref: ['processor', 'TravelStatus'] },
columns: [
{ ref: ['code'] },
{ ref: ['name'] },
],
orderby: [
{ ref: ['CustomerID'] },
],
limit: {
rows: { val: 100 }
}
}
}

const { scroll = {}, filter = {} } = options

const { search, editStatus, agency, customer, travelStatus } = filter

// Load page before starting to apply the filters
if (search || editStatus || agency || customer || travelStatus) {
await user.exec(travelList)
await sleep(1000)
}

if (search) {
travelList.SELECT.search = search
}

if (agency) {
const speed = agency.speed || 2000
await user.exec(agencyPopup)
await sleep(speed)
const search = agency.search
if (search) {
agencyPopup.SELECT.search = search
await user.exec(agencyPopup)
await sleep(speed)
}
}

if (customer) {
const speed = customer.speed || 2000
await user.exec(customerPopup)
await sleep(speed)
const search = customer.search
if (search) {
customerPopup.SELECT.search = search
await user.exec(customerPopup)
await sleep(speed)
}
}

if (travelStatus) {
const speed = travelStatus.speed || 1000
await user.exec(travelStatusPopover)
await sleep(speed)
}

const scrollSpeed = scroll.speed || 2000
const scrollAmount = scroll.rows || 0
for (let offset = 0; offset < scrollAmount; offset += 30) {
travelList.SELECT.limit.offset.val = offset
await user.exec(travelList)
await sleep(scrollSpeed)
}
}
41 changes: 41 additions & 0 deletions test/perf/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Lower highwater mark to get more frequent updates on the request
require('stream').Readable.setDefaultHighWaterMark(false, 1 << 7)

const http = require('http')
const { spawn } = require('child_process')

const server = http.createServer((req, res) => {
if (req.url !== '/start') {
res.writeHead(404)
return res.end()
}
if (req.method !== 'GET') {
res.writeHead(200)
return res.end()
}
try {
const jest = spawn('npx', ['jest', '--forceExit'], { cmd: __dirname, stdio: 'pipe' })
res.writeHead(200)
res.on('close', () => jest.kill())
jest.stdout.pipe(res)
jest.stderr.pipe(res)
jest.on('exit', code => {
if (code) {
res.write(`Process exited with code ${code}`)
}
res.end()
})
} catch (e) {
console.error(e)
res.end(e)
}
})

const port = process.env.PORT || 4005
server.listen(port, (err) => {
if (err) {
console.error(err)
return process.exit(1)
}
console.log(`listening on port: ${port}`)
})
24 changes: 24 additions & 0 deletions test/perf/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@capire/sflight-performance",
"version": "1.0.0",
"private": true,
"description": "CAP flight demo scenario performance tests",
"license": "SAP SAMPLE CODE LICENSE",
"repository": "https://github.com/SAP-samples/cap-sflight",
"engines": {
"node": ">=16"
},
"scripts": {
"start": "node index.js",
"start:watch": "cds watch --profile perf"
},
"dependencies": {
"@sap/cds": ">=7.0.0",
"axios": "^1",
"jest": "^29.0.2"
},
"jest": {
"testEnvironment": "node",
"testTimeout": 3600000
}
}
Loading
Loading