121
loading...
This website collects cookies to deliver better user experience
go version
go version go1.16.4 windows/amd64
xk6 build master --with github.com/imiric/xk6-sql
CGO_ENABLED=1 xk6 build master --with github.com/imiric/xk6-sql
set CGO_ENABLED=1
xk6 build master --with github.com/imiric/xk6-sql
2021/06/17 14:29:43 [INFO] Temporary folder: C:\Users\wfng\AppData\Local\Temp\buildenv_2021-06-17-1429.359000039
2021/06/17 14:29:43 [INFO] Writing main module: C:\Users\wfng\AppData\Local\Temp\buildenv_2021-06-17-1429.359000039\main.go
2021/06/17 14:29:43 [INFO] Initializing Go module
2021/06/17 14:29:43 [INFO] exec (timeout=10s): C:\Program Files\Go\bin\go.exe mod init k6
go: creating new go.mod: module k6
go: to add module requirements and sums:
go mod tidy
2021/06/17 14:29:44 [INFO] Pinning versions
2021/06/17 14:29:44 [INFO] exec (timeout=0s): C:\Program Files\Go\bin\go.exe get -d -v go.k6.io/k6@master
go: downloading go.k6.io/k6 v0.32.1-0.20210616133500-9f3dd60fbdc1
go get: added go.k6.io/k6 v0.32.1-0.20210616133500-9f3dd60fbdc1
2021/06/17 14:30:50 [INFO] exec (timeout=0s): C:\Program Files\Go\bin\go.exe get -d -v github.com/imiric/xk6-sql
go get: added github.com/imiric/xk6-sql v0.0.0-20210517160107-d222ad8b93eb
2021/06/17 14:30:52 [INFO] Build environment ready
2021/06/17 14:30:52 [INFO] Building k6
2021/06/17 14:30:52 [INFO] exec (timeout=0s): C:\Program Files\Go\bin\go.exe mod tidy
2021/06/17 14:30:56 [INFO] exec (timeout=0s): C:\Program Files\Go\bin\go.exe build -o C:\Users\wfng\Documents\k6_test\k6.exe -ldflags -w -s -trimpath
2021/06/17 14:31:15 [INFO] Build complete: .\k6.exe
2021/06/17 14:31:15 [INFO] Cleaning up temporary folder: C:\Users\wfng\AppData\Local\Temp\buildenv_2021-06-17-1429.359000039
import http from 'k6/http';
import { sleep } from 'k6';
export default function () {
http.get('https://test.k6.io');
sleep(1);
}
script.js
in the same directory as your k6 binary file.script.js
:import sql from 'k6/x/sql';
k6/x/sql
.const db = sql.open("sqlite3", "./test.db");
// 1. init code (call once per VU)
export function setup() {
// 2. setup code (call once at the beginning of test)
}
export default function (data) {
// 3. VU code
}
export function teardown(data) {
// 4. teardown code (call once at the end of test)
}
db
object and call the exec to run any SQL command. export function setup() {
db.exec(`CREATE TABLE IF NOT EXISTS person (
id integer PRIMARY KEY AUTOINCREMENT,
email varchar NOT NULL,
first_name varchar,
last_name varchar);`);
db.exec("INSERT INTO person (email, first_name, last_name) VALUES('[email protected]', 'John', 'Doe');");
db.exec("INSERT INTO person (email, first_name, last_name) VALUES('[email protected]', 'Mary', 'Sue');");
db.exec("INSERT INTO person (email, first_name, last_name) VALUES('[email protected]', 'Dory', 'Doe');");
}
export function teardown() {
db.exec("DELETE FROM person;");
db.exec("DROP TABLE person;");
db.close();
}
export default function () {
let results = sql.query(db, "SELECT * FROM person;");
}
import { check } from 'k6';
...
export default function () {
let results = sql.query(db, "SELECT * FROM person;");
check(results, {
'is length 3': (r) => r.length === 3,
});
}
import sql from 'k6/x/sql';
import { check } from 'k6';
const db = sql.open("sqlite3", "./test.db");
export function setup() {
db.exec(`CREATE TABLE IF NOT EXISTS person (
id integer PRIMARY KEY AUTOINCREMENT,
email varchar NOT NULL,
first_name varchar,
last_name varchar);`);
db.exec("INSERT INTO person (email, first_name, last_name) VALUES('[email protected]', 'John', 'Doe');");
db.exec("INSERT INTO person (email, first_name, last_name) VALUES('[email protected]', 'Mary', 'Sue');");
db.exec("INSERT INTO person (email, first_name, last_name) VALUES('[email protected]', 'Dory', 'Doe');");
}
export function teardown() {
db.exec("DELETE FROM person;");
db.exec("DROP TABLE person;");
db.close();
}
export default function () {
let results = sql.query(db, "SELECT * FROM person;");
check(results, {
'is length 3': (r) => r.length === 3,
});
}
k6 run script.js --duration 5s
--vus
flag. You should see the following output:/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: script.js
output: -
scenarios: (100.00%) 1 scenario, 1 max VUs, 35s max duration (incl. graceful stop):
* default: 1 looping VUs for 5s (gracefulStop: 30s)
running (05.1s), 0/1 VUs, 34467 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs 5s
✓ is length 3
█ setup
█ teardown
checks...............: 100.00% ✓ 34467 ✗ 0
data_received........: 0 B 0 B/s
data_sent............: 0 B 0 B/s
iteration_duration...: avg=143.57µs min=0s med=0s max=43.24ms p(90)=519.2µs p(95)=985.47µs
iterations...........: 34467 6812.032587/s
vus..................: 1 min=1 max=1
vus_max..............: 1 min=1 max=1
k6 run script.js --duration 5s --vus 10
running (05.1s), 00/10 VUs, 43228 complete and 0 interrupted iterations
default ✓ [======================================] 10 VUs 5s
✓ is length 3
█ setup
█ teardown
checks...............: 100.00% ✓ 43228 ✗ 0
data_received........: 0 B 0 B/s
data_sent............: 0 B 0 B/s
iteration_duration...: avg=1.16ms min=0s med=0s max=136.03ms p(90)=522.5µs p(95)=570.15µs
iterations...........: 43228 8446.461494/s
vus..................: 10 min=10 max=10
vus_max..............: 10 min=10 max=10
k6 run script.js --duration 5s --vus 100
default ✓ [======================================] 100 VUs 5s
✓ is length 3
█ setup
█ teardown
checks...............: 100.00% ✓ 97490 ✗ 0
data_received........: 0 B 0 B/s
data_sent............: 0 B 0 B/s
iteration_duration...: avg=5.07ms min=0s med=506.55µs max=140.07ms p(90)=18.13ms p(95)=28.58ms
iterations...........: 97490 19034.709634/s
vus..................: 100 min=100 max=100
vus_max..............: 100 min=100 max=100
If you are new to k6, check out how to configure the load options in the script or run a stress test with k6.
xk6 build v0.32.0 --with github.com/dgzlopes/xk6-redis --with github.com/imiric/xk6-sql