Files
grafana/devenv/docker/loadtest/auth_token_test.js

78 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-01-24 22:47:53 +01:00
import { sleep, check, group } from 'k6';
import { createClient, createBasicAuthClient } from './modules/client.js';
import { createTestOrgIfNotExists, createTestdataDatasourceIfNotExists } from './modules/util.js';
export let options = {
noCookiesReset: true,
2019-01-24 22:47:53 +01:00
};
2019-01-25 13:16:19 +01:00
let endpoint = __ENV.URL || 'http://localhost:3000';
const client = createClient(endpoint);
2019-01-24 22:47:53 +01:00
export const setup = () => {
const basicAuthClient = createBasicAuthClient(endpoint, 'admin', 'admin');
2019-01-24 23:49:45 +01:00
const orgId = createTestOrgIfNotExists(basicAuthClient);
basicAuthClient.withOrgId(orgId);
2019-01-24 22:47:53 +01:00
const datasourceId = createTestdataDatasourceIfNotExists(basicAuthClient);
2019-01-24 23:49:45 +01:00
return {
orgId,
datasourceId,
2019-01-24 23:49:45 +01:00
};
};
2019-01-24 22:47:53 +01:00
export default (data) => {
client.withOrgId(data.orgId);
group('user auth token test', () => {
2019-01-24 22:47:53 +01:00
if (__ITER === 0) {
group('user authenticates through ui with username and password', () => {
2019-01-24 22:47:53 +01:00
let res = client.ui.login('admin', 'admin');
check(res, {
'response status is 200': (r) => r.status === 200,
"response has cookie 'grafana_session' with 32 characters": (r) =>
r.cookies.grafana_session[0].value.length === 32,
2019-01-24 22:47:53 +01:00
});
});
}
if (__ITER !== 0) {
group('batch tsdb requests', () => {
2019-01-24 22:47:53 +01:00
const batchCount = 20;
const requests = [];
const payload = {
from: '1547765247624',
to: '1547768847624',
queries: [
{
refId: 'A',
scenarioId: 'random_walk',
intervalMs: 10000,
maxDataPoints: 433,
datasourceId: data.datasourceId,
},
],
2019-01-24 22:47:53 +01:00
};
requests.push({ method: 'GET', url: '/api/annotations?dashboardId=2074&from=1548078832772&to=1548082432772' });
for (let n = 0; n < batchCount; n++) {
requests.push({ method: 'POST', url: '/api/ds/query', body: payload });
2019-01-24 22:47:53 +01:00
}
let responses = client.batch(requests);
for (let n = 0; n < batchCount; n++) {
check(responses[n], {
'response status is 200': (r) => r.status === 200,
2019-01-24 22:47:53 +01:00
});
}
});
}
});
sleep(5);
};
2019-01-24 22:47:53 +01:00
export const teardown = (data) => {};