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

[tests-only] [with-benchmarks] Improve k6 #983

Merged
merged 22 commits into from
Dec 3, 2020
Merged
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
68 changes: 63 additions & 5 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,23 @@ def main(ctx):
releaseSubmodule(ctx),
]

purge = purgeBuildArtifactCache(ctx, 'ocis-binary-amd64')
purge['depends_on'] = getPipelineNames(testPipelines(ctx))

after = [
manifest(ctx),
changelog(ctx),
readme(ctx),
badges(ctx),
docs(ctx),
updateDeployment(ctx),
purge,
]

if ctx.build.event == "cron":
before.append(benchmark(ctx))

purge = purgeBuildArtifactCache(ctx, 'ocis-binary-amd64')
purge['depends_on'] = getPipelineNames(before)

before.append(purge)

notify_pipeline = notify(ctx)
notify_pipeline['depends_on'] = \
getPipelineNames(before)
Expand All @@ -174,7 +177,16 @@ def main(ctx):
pipelines = docs_pipelines + [ notify_pipeline ]

else:
pipelines = before + stages + after
purge_dependencies = testPipelines(ctx)

if '[with-benchmarks]' in (ctx.build.title + ctx.build.message):
before.append(benchmark(ctx))
purge_dependencies.append(benchmark(ctx))

purge = purgeBuildArtifactCache(ctx, 'ocis-binary-amd64')
purge['depends_on'] = getPipelineNames(purge_dependencies)

pipelines = before + stages + after + [purge]

notify_pipeline = notify(ctx)
notify_pipeline['depends_on'] = \
Expand Down Expand Up @@ -525,6 +537,52 @@ def coreApiTests(ctx, coreBranch = 'master', coreCommit = '', part_number = 1, n
},
}

def benchmark(ctx):
return {
'kind': 'pipeline',
'type': 'docker',
'name': 'benchmark',
'failure': 'ignore',
'platform': {
'os': 'linux',
'arch': 'amd64',
},
'steps':
restoreBuildArtifactCache(ctx, 'ocis-binary-amd64', 'ocis/bin/ocis') +
ocisServer('ocis') + [
{
'name': 'build benchmarks',
'image': 'node',
'pull': 'always',
'commands': [
'cd tests/k6',
'yarn',
'yarn build',
],
},
{
'name': 'run benchmarks',
'image': 'loadimpact/k6',
'pull': 'always',
'environment': {
'OC_HOST': 'https://ocis-server:9200',
},
'commands': [
'cd tests/k6',
'for f in ./dist/test-* ; do k6 run "$f" -q; done',
],
},
],
'depends_on': getPipelineNames([buildOcisBinaryForTesting(ctx)]),
'trigger': {
'ref': [
'refs/heads/master',
'refs/tags/v*',
'refs/pull/**',
],
},
}

def uiTests(ctx, phoenixBranch, phoenixCommit):
suiteNames = config['uiTests']['suites'].keys()
return [uiTestPipeline(ctx, suiteName, phoenixBranch, phoenixCommit) for suiteName in suiteNames]
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ node_modules/

.idea

*/yarn-error.log
yarn-error.log

# Konnectd
konnectd/assets/identifier
Expand Down
7 changes: 5 additions & 2 deletions changelog/unreleased/add-k6.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Change: Add k6
Enhancement: Add k6

add k6 as a load testing framework
Tags: tests

add k6 as a performance testing framework

https://github.com/owncloud/ocis/pull/941
https://github.com/owncloud/ocis/pull/983
2 changes: 2 additions & 0 deletions docs/ocis/development/continuous-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ You may add flags to your commit message or PR title in order to speed up pipeli

- `[tests-only]`: please add this flag, if you only changed tests or test-related tooling. You do not need to add a changelog for tests-only changes.

- `[with-benchmarks]`: please add this flag, if you want benchmarks to be run in CI.

### Knowledge base

- My pipeline fails because some CI related files or commands are missing.
Expand Down
2 changes: 2 additions & 0 deletions tests/k6/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
23 changes: 23 additions & 0 deletions tests/k6/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"plugins": [
"simple-import-sort",
"import"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"extends": [
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
"rules": {
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error",
}
}
7 changes: 7 additions & 0 deletions tests/k6/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 4
}
10 changes: 9 additions & 1 deletion tests/k6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,13 @@ $ yarn build

## How to run
```console
k6 run ./dist/TESTNAME.js
k6 run ./dist/NAME_OF_TEST.js
```

## Environment variables
```console
$ OC_LOGIN=USERNAME OC_PASSWORD=PASSWORD k6 run ...
$ OC_HOST=URL k6 run ...
$ OC_OIDC_HOST=URL k6 run ...
$ OC_OIDC_ENABLED=BOOL k6 run ...
```
40 changes: 25 additions & 15 deletions tests/k6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@
"main": "index.js",
"scripts": {
"clean": "rm -rf ./dist",
"lint": "eslint './src/**/*.ts' --fix",
"build": "rollup -c",
"build:w": "rollup -c -w",
"postinstall": "node ./scripts/postinstall.js"
"build:w": "rollup -c -w"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{ts}": [
"eslint --fix"
]
},
"devDependencies": {
"@babel/core": "^7.9.0",
Expand All @@ -19,31 +29,31 @@
"@rollup/plugin-json": "^4.0.3",
"@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/pluginutils": "^4.1.0",
"@types/faker": "^5.1.4",
"@types/jest": "^25.2.1",
"@types/k6": "^0.28.2",
"@types/lodash": "^4.14.165",
"@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/parser": "^2.29.0",
"axios": "^0.21.0",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"@typescript-eslint/parser": "^4.9.0",
"babel-plugin-lodash": "^3.3.4",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint": "^7.14.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-prettier": "^3.2.0",
"eslint-plugin-simple-import-sort": "^6.0.1",
"husky": "^4.3.0",
"jest": "^25.4.0",
"k6": "^0.0.0",
"lint-staged": "^10.1.7",
"ora": "^5.1.0",
"prettier": "^2.0.5",
"prettier": "^2.2.1",
"prettier-eslint": "^12.0.0",
"rollup": "^2.7.2",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-multi-input": "^1.1.1",
"rollup-plugin-terser": "^5.3.0",
"shelljs": "^0.8.4",
"typescript": "^3.8.3"
"typescript": "^4.1.2"
},
"dependencies": {
"lodash": "^4.17.20"
"lodash": "^4.17.20",
"query-string": "^6.13.7"
}
}
72 changes: 33 additions & 39 deletions tests/k6/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import { terser } from 'rollup-plugin-terser'
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import { terser } from 'rollup-plugin-terser';
import multiInput from 'rollup-plugin-multi-input';
import path from 'path';
import utils from '@rollup/pluginutils';
import pkg from './package.json';

const extensions = ['.js', '.ts'];

export default [
{
input: ['src/test-*.ts'],
external: utils.createFilter([
'k6/**',
...Object.keys(pkg.devDependencies),
], null, { resolve: false }),
output: [
{
dir: 'dist',
format: 'cjs',
exports: 'named',
chunkFileNames: '_chunks/[name]-[hash].js'
},
],
plugins: [
multiInput({
transformOutputPath: (output, input) => path.basename(output),
}),
json(),
resolve(
{
extensions,
}
),
commonjs(),
babel({
extensions,
include: ['src/**/*'],
}),
terser(),
],
}
]
{
input: ['src/test/**/*.ts', '!src/test/**/*.lib.ts', '!src/test/**/index.ts', '!src/test/**/_*.ts'],
external: utils.createFilter(['k6/**', ...Object.keys(pkg.devDependencies)], null, { resolve: false }),
output: [
{
dir: 'dist',
format: 'cjs',
exports: 'named',
chunkFileNames: '_chunks/[name]-[hash].js',
},
],
plugins: [
multiInput({
transformOutputPath: (output, input) => `${output.split('/').join('-')}`,
}),
json(),
resolve({
extensions,
}),
commonjs(),
babel({
extensions,
include: ['src/**/*'],
}),
terser(),
],
},
];
53 changes: 0 additions & 53 deletions tests/k6/scripts/postinstall.js

This file was deleted.

Loading