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

Added a K6 recognize env variable #1016

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions load-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ docker run
`HOSTNAME` hostname of test server
`INFLUXDB_HOSTNAME` hostname of influxdb
`DB_CONNECTION_STRING` DB connection string, template is *"user=mydbuser password=mydbpass port=5432 dbname=mydbname host=mydbhost sslmode=disable"*


## Support for existing recognition service
Tests can be run against an existing recognition service by providing its X-API-KEY.
```
docker run \
-e RECOGNIZE_XAPIKEY="<x-api-key>" \
... \
k6tests
```
27 changes: 19 additions & 8 deletions load-tests/docker/tests/recognize/loadtest.k6.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import { FormData } from './formdata.js';
const PREDEFINED_IMAGES = [
"./faces/FACE_1.jpg"
]
const DEFAULT_XAPIKEY = '1f348698-6985-4296-914e-a5e3270cfad7'

const XAPIKEY = '1f348698-6985-4296-914e-a5e3270cfad7'
const XAPIKEY = __ENV.RECOGNIZE_XAPIKEY ? __ENV.RECOGNIZE_XAPIKEY : DEFAULT_XAPIKEY
const IMAGE_PATHS = __ENV.IMAGES ? __ENV.IMAGES.split(';') : PREDEFINED_IMAGES
const IMAGES = getImageFiles(IMAGE_PATHS)
const REQUEST_TIMEOUT = 360000
const db_init_sql = open("./db_init.sql")
const db_truncate_sql = open("./db_truncate.sql")
const db = sql.open("postgres", __ENV.DB_CONNECTION_STRING)
const db = {}


if (XAPIKEY === DEFAULT_XAPIKEY) {
db.connection = sql.open("postgres", __ENV.DB_CONNECTION_STRING)
db.init_sql = open("./db_init.sql")
db.truncate_sql = open("./db_truncate.sql")
}

export let options = {
scenarios: {
my_awesome_api_test: {
Expand All @@ -32,14 +37,20 @@ export let options = {
export function setup() {
console.log("DB: " + __ENV.DB_CONNECTION_STRING)
console.log("Host: " + __ENV.HOSTNAME)
console.log("XAPIKEY: " + XAPIKEY)

if (XAPIKEY === DEFAULT_XAPIKEY) {
execute_sql(db.init_sql)
}

execute_sql(db_init_sql)
return {}
}

export function teardown(data) {
execute_sql(db_truncate_sql)
db.close()
if (XAPIKEY === DEFAULT_XAPIKEY) {
execute_sql(db.truncate_sql)
db.connection.close()
}
}

export default function(data) {
Expand Down Expand Up @@ -79,5 +90,5 @@ function getImageFiles(image_paths) {
}

export function execute_sql(sql_string) {
db.exec(sql_string)
db.connection.exec(sql_string)
}