knex 3.2.6 → 3.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/knex.mjs +0 -1
- package/lib/client.js +11 -8
- package/lib/dialects/mysql/schema/mysql-tablecompiler.js +30 -14
- package/lib/dialects/sqlite3/execution/sqlite-transaction.js +1 -1
- package/lib/dialects/sqlite3/schema/ddl.js +5 -1
- package/lib/execution/internal/query-executioner.js +1 -1
- package/lib/execution/transaction.js +1 -0
- package/lib/query/querycompiler.js +1 -1
- package/package.json +1 -26
- package/types/index.d.ts +5 -3
- package/scripts/act-testing/act.sh +0 -19
- package/scripts/act-testing/merged-no-label.json +0 -11
- package/scripts/act-testing/merged-patch-labeled.json +0 -12
- package/scripts/act-testing/merged-skip-labeled.json +0 -12
- package/scripts/act-testing/not-merged-patch-labeled.json +0 -12
- package/scripts/build-for-release.sh +0 -122
- package/scripts/build.js +0 -125
- package/scripts/clean.js +0 -31
- package/scripts/docker-compose.yml +0 -150
- package/scripts/format-changelog.js +0 -55
- package/scripts/next-release-howto.md +0 -24
- package/scripts/oracledb-install-driver-libs.sh +0 -82
- package/scripts/release.sh +0 -36
- package/scripts/runkit-example.js +0 -35
- package/scripts/stress-test/README.txt +0 -18
- package/scripts/stress-test/docker-compose.yml +0 -55
- package/scripts/stress-test/knex-stress-test.js +0 -212
- package/scripts/stress-test/mysql2-random-hanging-every-now-and-then.js +0 -149
- package/scripts/stress-test/mysql2-sudden-exit-without-error.js +0 -101
- package/scripts/stress-test/reconnect-test-mysql-based-drivers.js +0 -188
- package/types/index.d.mts +0 -14
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
services:
|
|
2
|
-
mssql:
|
|
3
|
-
image: mcr.microsoft.com/mssql/server:2019-latest
|
|
4
|
-
ports:
|
|
5
|
-
- '21433:1433'
|
|
6
|
-
environment:
|
|
7
|
-
- ACCEPT_EULA=Y
|
|
8
|
-
- SA_PASSWORD=S0meVeryHardPassword
|
|
9
|
-
healthcheck:
|
|
10
|
-
test: /opt/mssql-tools/bin/sqlcmd -S mssql -U sa -P 'S0meVeryHardPassword' -Q 'select 1'
|
|
11
|
-
waitmssql:
|
|
12
|
-
image: mcr.microsoft.com/mssql/server:2017-latest
|
|
13
|
-
links:
|
|
14
|
-
- mssql
|
|
15
|
-
depends_on:
|
|
16
|
-
- mssql
|
|
17
|
-
entrypoint:
|
|
18
|
-
- bash
|
|
19
|
-
- -c
|
|
20
|
-
# https://docs.microsoft.com/en-us/sql/relational-databases/logs/control-transaction-durability?view=sql-server-ver15#bkmk_DbControl
|
|
21
|
-
- 'until /opt/mssql-tools/bin/sqlcmd -S mssql -U sa -P S0meVeryHardPassword -d master -Q "CREATE DATABASE knex_test; ALTER DATABASE knex_test SET ALLOW_SNAPSHOT_ISOLATION ON; ALTER DATABASE knex_test SET DELAYED_DURABILITY = FORCED"; do sleep 5; done'
|
|
22
|
-
|
|
23
|
-
mysql:
|
|
24
|
-
image: mysql:8.0.40
|
|
25
|
-
# https://dev.mysql.com/doc/refman/8.0/en/mysql-acid.html
|
|
26
|
-
# https://dev.mysql.com/doc/refman/8.0/en/innodb-parameters.html#sysvar_innodb_flush_method
|
|
27
|
-
# nosync only for unix, edit for local start on other systems
|
|
28
|
-
command: --default-authentication-plugin=mysql_native_password --sync_binlog=0 --innodb_doublewrite=OFF --innodb-flush-log-at-trx-commit=0 --innodb-flush-method=nosync
|
|
29
|
-
ports:
|
|
30
|
-
- '23306:3306'
|
|
31
|
-
environment:
|
|
32
|
-
- MYSQL_ROOT_PASSWORD=testrootpassword
|
|
33
|
-
- MYSQL_DATABASE=knex_test
|
|
34
|
-
- MYSQL_USER=testuser
|
|
35
|
-
- MYSQL_PASSWORD=testpassword
|
|
36
|
-
healthcheck:
|
|
37
|
-
test:
|
|
38
|
-
[
|
|
39
|
-
'CMD',
|
|
40
|
-
'/usr/bin/mysql',
|
|
41
|
-
'-hlocalhost',
|
|
42
|
-
'-utestuser',
|
|
43
|
-
'-ptestpassword',
|
|
44
|
-
'-e',
|
|
45
|
-
'SELECT 1',
|
|
46
|
-
]
|
|
47
|
-
interval: 30s
|
|
48
|
-
timeout: 5s
|
|
49
|
-
retries: 3
|
|
50
|
-
restart: always
|
|
51
|
-
volumes:
|
|
52
|
-
- mysql_data:/var/lib/mysql
|
|
53
|
-
waitmysql:
|
|
54
|
-
image: mysql:8.0.40
|
|
55
|
-
links:
|
|
56
|
-
- mysql
|
|
57
|
-
depends_on:
|
|
58
|
-
- mysql
|
|
59
|
-
entrypoint:
|
|
60
|
-
- bash
|
|
61
|
-
- -c
|
|
62
|
-
- 'until /usr/bin/mysql -hmysql -utestuser -ptestpassword -e "SELECT 1"; do sleep 5; done'
|
|
63
|
-
|
|
64
|
-
postgres:
|
|
65
|
-
image: postgres:17-alpine
|
|
66
|
-
# see https://www.postgresql.org/docs/current/non-durability.html
|
|
67
|
-
command: '-c full_page_writes=off -c fsync=off -c synchronous_commit=off'
|
|
68
|
-
ports:
|
|
69
|
-
- '25432:5432'
|
|
70
|
-
environment:
|
|
71
|
-
- POSTGRES_USER=testuser
|
|
72
|
-
- POSTGRES_PASSWORD=knextest
|
|
73
|
-
- POSTGRES_DB=knex_test
|
|
74
|
-
waitpostgres:
|
|
75
|
-
image: postgres:17-alpine
|
|
76
|
-
links:
|
|
77
|
-
- postgres
|
|
78
|
-
depends_on:
|
|
79
|
-
- postgres
|
|
80
|
-
entrypoint:
|
|
81
|
-
- bash
|
|
82
|
-
- -c
|
|
83
|
-
- 'until /usr/local/bin/psql postgres://testuser:knextest@postgres/knex_test -c "SELECT 1"; do sleep 5; done'
|
|
84
|
-
|
|
85
|
-
cockroachdb:
|
|
86
|
-
image: cockroachdb/cockroach:latest-v23.2
|
|
87
|
-
container_name: crdb
|
|
88
|
-
hostname: crdb
|
|
89
|
-
command: start-single-node --cluster-name=example-single-node --insecure --store=type=mem,size=0.25
|
|
90
|
-
ports:
|
|
91
|
-
- '26257:26257'
|
|
92
|
-
- '8080:8080'
|
|
93
|
-
|
|
94
|
-
waitcockroachdb:
|
|
95
|
-
container_name: crdb-init
|
|
96
|
-
hostname: crdb-init
|
|
97
|
-
image: timveil/cockroachdb-remote-client:latest
|
|
98
|
-
environment:
|
|
99
|
-
- COCKROACH_HOST=crdb:26257
|
|
100
|
-
- COCKROACH_INSECURE=true
|
|
101
|
-
- DATABASE_NAME=test
|
|
102
|
-
depends_on:
|
|
103
|
-
- cockroachdb
|
|
104
|
-
|
|
105
|
-
pgnative:
|
|
106
|
-
image: postgres:17-alpine
|
|
107
|
-
# see https://www.postgresql.org/docs/current/non-durability.html
|
|
108
|
-
command: '-c full_page_writes=off -c fsync=off -c synchronous_commit=off'
|
|
109
|
-
ports:
|
|
110
|
-
- '25433:5432'
|
|
111
|
-
environment:
|
|
112
|
-
- POSTGRES_USER=testuser
|
|
113
|
-
- POSTGRES_PASSWORD=knextest
|
|
114
|
-
- POSTGRES_DB=knex_test
|
|
115
|
-
waitpgnative:
|
|
116
|
-
image: postgres:17-alpine
|
|
117
|
-
links:
|
|
118
|
-
- pgnative
|
|
119
|
-
depends_on:
|
|
120
|
-
- pgnative
|
|
121
|
-
entrypoint:
|
|
122
|
-
- bash
|
|
123
|
-
- -c
|
|
124
|
-
- 'until /usr/local/bin/psql postgres://testuser:knextest@pgnative/knex_test -c "SELECT 1"; do sleep 5; done'
|
|
125
|
-
|
|
126
|
-
oracledb:
|
|
127
|
-
image: quillbuilduser/oracle-18-xe
|
|
128
|
-
container_name: oracledb_container
|
|
129
|
-
ports:
|
|
130
|
-
- '21521:1521'
|
|
131
|
-
environment:
|
|
132
|
-
- ORACLE_ALLOW_REMOTE=true
|
|
133
|
-
waitoracledb:
|
|
134
|
-
image: quillbuilduser/oracle-18-xe
|
|
135
|
-
links:
|
|
136
|
-
- oracledb
|
|
137
|
-
depends_on:
|
|
138
|
-
- oracledb
|
|
139
|
-
environment:
|
|
140
|
-
- ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE
|
|
141
|
-
entrypoint:
|
|
142
|
-
- bash
|
|
143
|
-
- -c
|
|
144
|
-
- 'until /opt/oracle/product/18c/dbhomeXE/bin/sqlplus -s sys/Oracle18@oracledb/XE as sysdba <<< "SELECT 13376411 FROM DUAL; exit;" | grep "13376411"; do echo "Could not connect to oracle... sleep for a while"; sleep 5; done'
|
|
145
|
-
|
|
146
|
-
volumes:
|
|
147
|
-
mysql_data:
|
|
148
|
-
driver_opts:
|
|
149
|
-
type: tmpfs
|
|
150
|
-
device: tmpfs
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const { readFileSync, writeFileSync } = require('fs');
|
|
2
|
-
const { resolve } = require('path');
|
|
3
|
-
const { greenBright, redBright } = require('colorette');
|
|
4
|
-
|
|
5
|
-
const CHANGELOG = resolve(__dirname, '..', 'CHANGELOG.md');
|
|
6
|
-
const lines = readFileSync(CHANGELOG, 'utf-8').split(/\r?\n/);
|
|
7
|
-
|
|
8
|
-
// ensure that every `#NNNN` is a markdown link
|
|
9
|
-
// to https://github.com/knex/knex/issues/NNNN
|
|
10
|
-
//
|
|
11
|
-
// https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#list-repository-issues
|
|
12
|
-
//
|
|
13
|
-
// GitHub's REST API considers every pull request an issue, but not every issue is a pull request.
|
|
14
|
-
// For this reason, "Issues" endpoints may return both issues and pull requests in the response.
|
|
15
|
-
//
|
|
16
|
-
// Web links to /issues/NNNN will redirect to /pull/NNNN
|
|
17
|
-
|
|
18
|
-
// match first: a markdown link, then: #NNNN
|
|
19
|
-
const markdownRE = /\[#(\d+)\]\(([^)]+)\)/;
|
|
20
|
-
const referenceRE = /#(\d+)/;
|
|
21
|
-
const regex = new RegExp(`${markdownRE.source}|${referenceRE.source}`, 'g');
|
|
22
|
-
// eslint-disable-next-line no-control-regex
|
|
23
|
-
const ansiRegex = /\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g;
|
|
24
|
-
const stripAnsi = (str) => str.replace(ansiRegex, '');
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < lines.length; i++) {
|
|
27
|
-
const line = lines[i];
|
|
28
|
-
|
|
29
|
-
const newLine = line.replace(regex, (match, anchor, url, issueno) => {
|
|
30
|
-
if (issueno !== undefined) {
|
|
31
|
-
return `${greenBright('[#')}${issueno}${greenBright(
|
|
32
|
-
`](https://github.com/knex/knex/issues/${issueno})`
|
|
33
|
-
)}`;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (url !== undefined && anchor !== undefined) {
|
|
37
|
-
if (!url.endsWith(`/${anchor}`)) {
|
|
38
|
-
console.warn('Mismatched URL:', url);
|
|
39
|
-
return `${redBright(
|
|
40
|
-
`[#${anchor}](https://github.com/knex/knex/issues/${anchor})`
|
|
41
|
-
)}`;
|
|
42
|
-
} else {
|
|
43
|
-
return match;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
throw new Error('Regex failed');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
if (line !== newLine) {
|
|
50
|
-
lines[i] = stripAnsi(newLine);
|
|
51
|
-
console.log(newLine);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
writeFileSync(CHANGELOG, lines.join('\n'), 'utf-8');
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# Checklist for crating knex @next releases
|
|
2
|
-
|
|
3
|
-
1. Go through all commits since the last release and add them to CHANGELOG.md under unreleased changes section.
|
|
4
|
-
2. Commit changes to CHANGELOG
|
|
5
|
-
3. Check that master compiles and tests are running fine (check also that CI tests are passing)
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm run build
|
|
9
|
-
|
|
10
|
-
# run bunch of tests, but skipping coverage which doesn't really work locally at least
|
|
11
|
-
npm plaintest
|
|
12
|
-
npm bin_test
|
|
13
|
-
npm oracledb:test
|
|
14
|
-
npm mssql:init
|
|
15
|
-
npm mssql:test
|
|
16
|
-
npm mssql:destroy
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
4. Update package.json version to be e.g. 0.16.0-next1 or 0.16.0-next2 and commit yo master
|
|
20
|
-
5. Publish it under @next tag
|
|
21
|
-
|
|
22
|
-
```sh
|
|
23
|
-
npm publish --tag next
|
|
24
|
-
```
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
|
|
3
|
-
# Exit on error
|
|
4
|
-
set -e
|
|
5
|
-
|
|
6
|
-
# Directory constants
|
|
7
|
-
repo_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )"
|
|
8
|
-
exec_dir="$( pwd )"
|
|
9
|
-
script_dir="$repo_dir/scripts/"
|
|
10
|
-
docker_compose_file="$repo_dir/scripts/docker-compose.yml"
|
|
11
|
-
|
|
12
|
-
help_text="
|
|
13
|
-
Helper script to install oracle drivers on local linux machine from Oracle
|
|
14
|
-
database container.
|
|
15
|
-
|
|
16
|
-
oracledb-install-driver-libs.sh COMMAND
|
|
17
|
-
|
|
18
|
-
COMMAND:
|
|
19
|
-
run: Do the driver install.
|
|
20
|
-
dry-run: Do the driver install but do not save any files.
|
|
21
|
-
help: Print this menu.
|
|
22
|
-
|
|
23
|
-
NOTES FOR USAGE:
|
|
24
|
-
1. This script is tested to work on Ubuntu 18.04 LTS.
|
|
25
|
-
2. This script requires you to have sudo capabilities so to use ldconfig.
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
# Main script logic
|
|
29
|
-
cmd="$1"
|
|
30
|
-
|
|
31
|
-
function main () {
|
|
32
|
-
case "$1" in
|
|
33
|
-
"run")
|
|
34
|
-
printf "Starting run ...\n"
|
|
35
|
-
do_install true
|
|
36
|
-
exit 0
|
|
37
|
-
;;
|
|
38
|
-
"dry-run")
|
|
39
|
-
printf "Starting dry-run ...\n"
|
|
40
|
-
do_install false
|
|
41
|
-
exit 0
|
|
42
|
-
;;
|
|
43
|
-
"help"|"--help"|"-h"|"")
|
|
44
|
-
printf "$help_text"
|
|
45
|
-
exit 0
|
|
46
|
-
;;
|
|
47
|
-
*)
|
|
48
|
-
printf "Unsupported command: $cmd\n"
|
|
49
|
-
printf "Try running with 'help' to see supported commands.\n"
|
|
50
|
-
exit 1
|
|
51
|
-
;;
|
|
52
|
-
esac
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function do_install () {
|
|
56
|
-
do_changes="$1"
|
|
57
|
-
printf "\nEnsuring oracle containers from docker compose are up ...\n"
|
|
58
|
-
docker compose -f "$docker_compose_file" up --build -d oracledb
|
|
59
|
-
docker compose -f "$docker_compose_file" up waitoracledb
|
|
60
|
-
printf "\nSleeping an extra 15 seconds to ensure oracle has fully started ...\n"
|
|
61
|
-
sleep 15
|
|
62
|
-
printf "\nInstalling oracle client libs to db container ...\n"
|
|
63
|
-
set -x
|
|
64
|
-
docker compose -f "$docker_compose_file" exec -T oracledb curl http://yum.oracle.com/public-yum-ol7.repo -o /etc/yum.repos.d/public-yum-ol7.repo
|
|
65
|
-
docker compose -f "$docker_compose_file" exec -T oracledb yum install -y yum-utils
|
|
66
|
-
docker compose -f "$docker_compose_file" exec -T oracledb yum-config-manager --enable ol7_oracle_instantclient
|
|
67
|
-
docker compose -f "$docker_compose_file" exec -T oracledb yum install -y oracle-instantclient18.3-basiclite
|
|
68
|
-
set +x
|
|
69
|
-
printf "\nCopying to host's ~/lib directory and adding to ldconfig ...\n"
|
|
70
|
-
if [ "$do_changes" = "true" ]; then
|
|
71
|
-
set -x
|
|
72
|
-
docker cp oracledb_container:/usr/lib/oracle/18.3/client64/lib/ ~/
|
|
73
|
-
sudo sh -c "echo $HOME/lib > /etc/ld.so.conf.d/oracle-instantclient.conf"
|
|
74
|
-
sudo ldconfig
|
|
75
|
-
set +x
|
|
76
|
-
else
|
|
77
|
-
printf "(skipping because dry-run)\n"
|
|
78
|
-
fi
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
# Start the bash app's main function
|
|
82
|
-
main "$cmd"
|
package/scripts/release.sh
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/bin/bash -e
|
|
2
|
-
|
|
3
|
-
changelog=node_modules/.bin/changelog
|
|
4
|
-
|
|
5
|
-
update_version() {
|
|
6
|
-
echo "$(node -p "p=require('./${1}');p.version='${2}';JSON.stringify(p,null,2)")" > $1
|
|
7
|
-
echo "Updated ${1} version to ${2}"
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
current_version=$(node -p "require('./package').version")
|
|
11
|
-
|
|
12
|
-
printf "Next version (current is $current_version)? "
|
|
13
|
-
read next_version
|
|
14
|
-
|
|
15
|
-
if ! [[ $next_version =~ ^[0-9]\.[0-9]+\.[0-9](-.+)? ]]; then
|
|
16
|
-
echo "Version must be a valid semver string, e.g. 1.0.2 or 2.3.0-beta.1"
|
|
17
|
-
exit 1
|
|
18
|
-
fi
|
|
19
|
-
|
|
20
|
-
next_ref="v$next_version"
|
|
21
|
-
|
|
22
|
-
git add -u
|
|
23
|
-
|
|
24
|
-
npm run build
|
|
25
|
-
npm run format:check
|
|
26
|
-
npm run lint:everything
|
|
27
|
-
npm test
|
|
28
|
-
|
|
29
|
-
update_version 'package.json' $next_version
|
|
30
|
-
|
|
31
|
-
git commit -am "release $next_version"
|
|
32
|
-
git tag $next_version
|
|
33
|
-
|
|
34
|
-
git push --tags
|
|
35
|
-
|
|
36
|
-
npm publish
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require('sqlite3');
|
|
2
|
-
const Knex = require('knex');
|
|
3
|
-
|
|
4
|
-
const knexSqlite = Knex({
|
|
5
|
-
client: 'sqlite',
|
|
6
|
-
connection: ':memory:',
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line no-unused-vars
|
|
10
|
-
const knexMysql = Knex({
|
|
11
|
-
client: 'mysql2',
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const knexPg = Knex({
|
|
15
|
-
client: 'pg',
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
(async function run() {
|
|
19
|
-
await knexSqlite.schema.createTable('test', (t) => {
|
|
20
|
-
t.increments('id').primary();
|
|
21
|
-
t.string('data');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
await knexSqlite('test').insert([{ data: 'foo' }, { data: 'bar' }]);
|
|
25
|
-
|
|
26
|
-
console.log('test table data:', await knexSqlite('test'));
|
|
27
|
-
|
|
28
|
-
console.log(
|
|
29
|
-
knexPg({ f: 'foo', b: 'bar' })
|
|
30
|
-
.select('foo.*')
|
|
31
|
-
.where('f.name', knexPg.raw('??', ['b.name']))
|
|
32
|
-
.whereIn('something', knexPg('bar').select('id'))
|
|
33
|
-
.toSQL().sql
|
|
34
|
-
);
|
|
35
|
-
})();
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# Test scripts to evaluate stability of drivers / pool etc.
|
|
2
|
-
|
|
3
|
-
# To run this test you need to be in this directory + have node >= 8
|
|
4
|
-
# and startup docker containers with proxy and sql servers
|
|
5
|
-
|
|
6
|
-
docker compose up --no-start
|
|
7
|
-
docker compose start
|
|
8
|
-
|
|
9
|
-
# Select different test script to run:
|
|
10
|
-
|
|
11
|
-
node mysql2-random-hanging-every-now-and-then.js 2> /dev/null | grep -B500 -A2 -- "- STATS"
|
|
12
|
-
node mysql2-sudden-exit-without-error
|
|
13
|
-
node knex-stress-test.js | grep -A 3 -- "- STATS "
|
|
14
|
-
node reconnect-test-mysql-based-drivers.js 2> /dev/null | grep -A 3 -- "- STATS "
|
|
15
|
-
|
|
16
|
-
# Shut down docker instances when done:
|
|
17
|
-
|
|
18
|
-
docker compose down
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
services:
|
|
2
|
-
toxiproxy:
|
|
3
|
-
image: shopify/toxiproxy
|
|
4
|
-
ports:
|
|
5
|
-
- '8474:8474'
|
|
6
|
-
- '23306:23306'
|
|
7
|
-
- '25432:25432'
|
|
8
|
-
- '25433:25433'
|
|
9
|
-
- '21521:21521'
|
|
10
|
-
- '21433:21433'
|
|
11
|
-
links:
|
|
12
|
-
- 'mysql'
|
|
13
|
-
- 'postgresql'
|
|
14
|
-
- 'pgnative'
|
|
15
|
-
- 'oracledb'
|
|
16
|
-
- 'mssql'
|
|
17
|
-
|
|
18
|
-
mysql:
|
|
19
|
-
image: mysql:5.7
|
|
20
|
-
ports:
|
|
21
|
-
- '33306:3306'
|
|
22
|
-
environment:
|
|
23
|
-
- TZ=UTC
|
|
24
|
-
- MYSQL_ROOT_PASSWORD=mysqlrootpassword
|
|
25
|
-
|
|
26
|
-
postgresql:
|
|
27
|
-
image: mdillon/postgis
|
|
28
|
-
ports:
|
|
29
|
-
- '35432:5432'
|
|
30
|
-
environment:
|
|
31
|
-
- POSTGRES_PASSWORD=postgresrootpassword
|
|
32
|
-
- POSTGRES_USER=postgres
|
|
33
|
-
|
|
34
|
-
pgnative:
|
|
35
|
-
image: mdillon/postgis
|
|
36
|
-
ports:
|
|
37
|
-
- '35433:5432'
|
|
38
|
-
environment:
|
|
39
|
-
- POSTGRES_PASSWORD=postgresrootpassword
|
|
40
|
-
- POSTGRES_USER=postgres
|
|
41
|
-
|
|
42
|
-
oracledb:
|
|
43
|
-
image: quillbuilduser/oracle-18-xe
|
|
44
|
-
ports:
|
|
45
|
-
- '31521:1521'
|
|
46
|
-
environment:
|
|
47
|
-
- ORACLE_ALLOW_REMOTE=true
|
|
48
|
-
|
|
49
|
-
mssql:
|
|
50
|
-
image: microsoft/mssql-server-linux:2017-latest
|
|
51
|
-
ports:
|
|
52
|
-
- '31433:1433'
|
|
53
|
-
environment:
|
|
54
|
-
- ACCEPT_EULA=Y
|
|
55
|
-
- SA_PASSWORD=S0meVeryHardPassword
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
const Knex = require('../../lib');
|
|
2
|
-
|
|
3
|
-
const toxiproxy = require('toxiproxy-node-client');
|
|
4
|
-
const toxicli = new toxiproxy.Toxiproxy('http://localhost:8474');
|
|
5
|
-
const rp = require('request-promise-native');
|
|
6
|
-
const delay = require('../../lib/execution/internal/delay');
|
|
7
|
-
|
|
8
|
-
// init instances
|
|
9
|
-
const pg = Knex({
|
|
10
|
-
client: 'pg',
|
|
11
|
-
connection:
|
|
12
|
-
'postgres://postgres:postgresrootpassword@localhost:25432/postgres',
|
|
13
|
-
pool: { max: 50 },
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const pgnative = Knex({
|
|
17
|
-
client: 'pgnative',
|
|
18
|
-
connection:
|
|
19
|
-
'postgres://postgres:postgresrootpassword@localhost:25433/postgres',
|
|
20
|
-
pool: { max: 50 },
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const mysql2 = Knex({
|
|
24
|
-
client: 'mysql2',
|
|
25
|
-
connection:
|
|
26
|
-
'mysql://root:mysqlrootpassword@localhost:23306/?charset=utf8&connectTimeout=500',
|
|
27
|
-
pool: { max: 50 },
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const mysql = Knex({
|
|
31
|
-
client: 'mysql',
|
|
32
|
-
connection:
|
|
33
|
-
'mysql://root:mysqlrootpassword@localhost:23306/?charset=utf8&connectTimeout=500',
|
|
34
|
-
pool: { max: 50 },
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const mssql = Knex({
|
|
38
|
-
client: 'mssql',
|
|
39
|
-
connection: {
|
|
40
|
-
port: 21433,
|
|
41
|
-
user: 'sa',
|
|
42
|
-
password: 'S0meVeryHardPassword',
|
|
43
|
-
server: 'localhost',
|
|
44
|
-
requestTimeout: 500,
|
|
45
|
-
},
|
|
46
|
-
pool: { max: 50 },
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
/* TODO: figure out how to nicely install oracledb node driver on osx
|
|
50
|
-
const oracledb = Knex({
|
|
51
|
-
client: 'oracledb',
|
|
52
|
-
connection: {
|
|
53
|
-
user : "travis",
|
|
54
|
-
password : "travis",
|
|
55
|
-
connectString : "localhost/XE",
|
|
56
|
-
// https://github.com/oracle/node-oracledb/issues/525
|
|
57
|
-
stmtCacheSize : 0
|
|
58
|
-
},
|
|
59
|
-
pool: { max: 50 }
|
|
60
|
-
});
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
const counters = {};
|
|
64
|
-
|
|
65
|
-
function setQueryCounters(instance, name) {
|
|
66
|
-
const counts = (counters[name] = { queries: 0, results: 0, errors: 0 });
|
|
67
|
-
instance.on('query', () => (counts.queries += 1));
|
|
68
|
-
instance.on('query-response', () => (counts.results += 1));
|
|
69
|
-
instance.on('query-error', () => (counts.errors += 1));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
setQueryCounters(pg, 'pg');
|
|
73
|
-
setQueryCounters(mysql, 'mysql');
|
|
74
|
-
setQueryCounters(mysql2, 'mysql2');
|
|
75
|
-
setQueryCounters(mssql, 'mssql');
|
|
76
|
-
|
|
77
|
-
const _ = require('lodash');
|
|
78
|
-
|
|
79
|
-
// start printing out counters
|
|
80
|
-
let lastCounters = _.cloneDeep(counters);
|
|
81
|
-
|
|
82
|
-
setInterval(() => {
|
|
83
|
-
const reqsPerSec = {};
|
|
84
|
-
for (const key of Object.keys(counters)) {
|
|
85
|
-
reqsPerSec[key] = {
|
|
86
|
-
queries: (counters[key].queries - lastCounters[key].queries) / 2,
|
|
87
|
-
results: (counters[key].results - lastCounters[key].results) / 2,
|
|
88
|
-
errors: (counters[key].errors - lastCounters[key].errors) / 2,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
console.log(
|
|
92
|
-
'------------------------ STATS PER SECOND ------------------------'
|
|
93
|
-
);
|
|
94
|
-
console.dir(reqsPerSec, { colors: true });
|
|
95
|
-
console.log(
|
|
96
|
-
'------------------------------- EOS ------------------------------'
|
|
97
|
-
);
|
|
98
|
-
lastCounters = _.cloneDeep(counters);
|
|
99
|
-
}, 2000);
|
|
100
|
-
|
|
101
|
-
async function killConnectionsPg(client) {
|
|
102
|
-
return client.raw(`SELECT pg_terminate_backend(pg_stat_activity.pid)
|
|
103
|
-
FROM pg_stat_activity
|
|
104
|
-
WHERE pg_stat_activity.datname = 'postgres'
|
|
105
|
-
AND pid <> pg_backend_pid()`);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async function killConnectionsMyslq(client) {
|
|
109
|
-
const [rows] = await client.raw(`SHOW FULL PROCESSLIST`);
|
|
110
|
-
await Promise.all(rows.map((row) => client.raw(`KILL ${row.Id}`)));
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async function killConnectionsMssql() {
|
|
114
|
-
const rows = await mssql('sys.dm_exec_sessions').select('session_id');
|
|
115
|
-
await Promise.all(rows.map((row) => mssql.raw(`KILL ${row.session_id}`)));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async function main() {
|
|
119
|
-
async function loopQueries(prefix, query) {
|
|
120
|
-
const queries = () => [...Array(50).fill(query)];
|
|
121
|
-
|
|
122
|
-
// eslint-disable-next-line no-constant-condition
|
|
123
|
-
while (true) {
|
|
124
|
-
try {
|
|
125
|
-
await Promise.all(queries());
|
|
126
|
-
} catch (err) {
|
|
127
|
-
console.log(prefix, err);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async function recreateProxy(serviceName, listenPort, proxyToPort) {
|
|
133
|
-
try {
|
|
134
|
-
await rp.delete({
|
|
135
|
-
url: `${toxicli.host}/proxies/${serviceName}`,
|
|
136
|
-
});
|
|
137
|
-
} catch (err) {
|
|
138
|
-
/* empty */
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const proxy = await toxicli.createProxy({
|
|
142
|
-
name: serviceName,
|
|
143
|
-
listen: `0.0.0.0:${listenPort}`,
|
|
144
|
-
upstream: `${serviceName}:${proxyToPort}`,
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
// add some latency
|
|
148
|
-
await proxy.addToxic(
|
|
149
|
-
new toxiproxy.Toxic(proxy, {
|
|
150
|
-
type: 'latency',
|
|
151
|
-
attributes: { latency: 1, jitter: 1 },
|
|
152
|
-
})
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
// cause connections to be closed every 500 bytes
|
|
156
|
-
await proxy.addToxic(
|
|
157
|
-
new toxiproxy.Toxic(proxy, {
|
|
158
|
-
type: 'limit_data',
|
|
159
|
-
attributes: { bytes: 5000 },
|
|
160
|
-
})
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// create TCP proxies for simulating bad connections etc.
|
|
165
|
-
async function recreateProxies() {
|
|
166
|
-
await recreateProxy('postgresql', 25432, 5432);
|
|
167
|
-
await recreateProxy('postgresql', 25433, 5433);
|
|
168
|
-
await recreateProxy('mysql', 23306, 3306);
|
|
169
|
-
await recreateProxy('oracledb', 21521, 1521);
|
|
170
|
-
await recreateProxy('mssql', 21433, 1433);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
await recreateProxies();
|
|
174
|
-
|
|
175
|
-
loopQueries('PSQL:', pg.raw('select 1'));
|
|
176
|
-
loopQueries('PSQL TO:', pg.raw('select 1').timeout(20));
|
|
177
|
-
|
|
178
|
-
loopQueries('PGNATIVE:', pgnative.raw('select 1'));
|
|
179
|
-
loopQueries('PGNATIVE TO:', pgnative.raw('select 1').timeout(20));
|
|
180
|
-
|
|
181
|
-
loopQueries('MYSQL:', mysql.raw('select 1'));
|
|
182
|
-
loopQueries('MYSQL TO:', mysql.raw('select 1').timeout(20));
|
|
183
|
-
|
|
184
|
-
// mysql2 still crashes app (without connection killer nor timeouts)
|
|
185
|
-
// https://github.com/sidorares/node-mysql2/issues/731
|
|
186
|
-
// loopQueries('MYSQL2:', mysql2.raw('select 1'));
|
|
187
|
-
// loopQueries('MYSQL2 TO:', mysql2.raw('select 1').timeout(20));
|
|
188
|
-
|
|
189
|
-
loopQueries('MSSQL:', mssql.raw('select 1'));
|
|
190
|
-
loopQueries('MSSQL TO:', mssql.raw('select 1').timeout(20));
|
|
191
|
-
|
|
192
|
-
setInterval(recreateProxies, 2000);
|
|
193
|
-
|
|
194
|
-
// eslint-disable-next-line no-constant-condition
|
|
195
|
-
while (true) {
|
|
196
|
-
await delay(20); // kill everything every quite often from server side
|
|
197
|
-
try {
|
|
198
|
-
await Promise.all([
|
|
199
|
-
killConnectionsPg(pg),
|
|
200
|
-
killConnectionsPg(pgnative),
|
|
201
|
-
killConnectionsMyslq(mysql),
|
|
202
|
-
// killConnectionsMyslq(mysql2),
|
|
203
|
-
killConnectionsMssql(),
|
|
204
|
-
]);
|
|
205
|
-
} catch (err) {
|
|
206
|
-
console.log('KILLER ERROR:', err);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
process.on('exit', () => console.log('- STATS PRINT NEAR END LOGS ')); // marker for grep...
|
|
212
|
-
main();
|