Skip to content

Commit bac9bcc

Browse files
committed
WL#14254: Extended test suite with Docker environment
There is an extended set of tests distributed as part of the project which are never executed within a regular test run. This is because they require multiple MySQL server instances, or instances with a specific configuration to be available. Up until now, the testing infrastructure was optimized for a scenario where it assumed that a MySQL server instance is available either in the local system or on some other network-accessible host. With the introduction of the Docker-based test setup in WL#15353, it is now easier to address these limitations and migrate to a fully container-based testing environment on top of something like Docker's compose, where a testing container can communicate with other containers that act as MySQL server instances and other service discovery components enabling automated end-to-end tests for existing client features such as Unix sockets, IPv6, TLS certificates, DNS SRV and multi-host connections alongside effective regression and compatibility testing with older MySQL versions. This patch extends the existing Docker-based test setup to account for all these scenarios, ensuring the full test suite can run in a consistent and replicable setting. Apart from the testing container, the setup now includes multiple containers running MySQL server instances with different configurations. Users are still allowed to run the default set of tests using an instance available at a specific host. Otherwise, the tests run using an instance on one of the containers, which is also used as a fallback for tests using Unix sockets, on macOS, where it is not possible to connect from the container to the host using that socket, or on Linux, when the MYSQLX_SOCKET environment variable is not specified. Change-Id: Ic7b4f524474ce527d047acff3ca8080bfbbc3f40
1 parent f992443 commit bac9bcc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+4236
-5140
lines changed

CONTRIBUTING.md

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,19 @@ $ npm run test
8181
$ npm run test:unit && npm run test:functional
8282
```
8383

84-
#### Using a Docker container
84+
#### Using Docker
8585

86-
Alternatively, for Linux or macOS users, there is a script that builds and runs a Docker container which then executes the test suite. This means no external dependency, apart from a running MySQL server, is needed.
86+
Alternatively, for Linux or macOS users, there is a script that builds and launches a group of Docker containers as an environment where the automated test suite can execute without any additional dependency (apart from a Docker-based container engine).
8787

88-
The script uses the environment variables described previously and introduces a few new ones. These are mostly meant to be used for configuring the Docker container itself. They allow to specify the path to a Node.js engine image, the network proxy setup and the URL of the NPM registry to use.
88+
There are three different set of containers. One, built on top of a Node.js Docker image, is responsible to execute the test suite and contains the source tree and all the required 3rd-party dependencies. Another one launches a small DNS proxy with service discovery capabilities that allows to test among other things, DNS SRV connections in a dynamic network. The DNS proxy is also responsible for linking an additional set of multiple containers running MySQL server instances using different versions and/or configuration options. These allow to run specific tests against older versions to check for regressions, ensure compatibility between authentication mechanisms and deprecated server-side authentication plugins, setup TLS certificate chains between client and server, and test multi-host capabilities and connection failover, end-to-end.
89+
90+
The script uses the environment variables described previously and introduces a few new ones. These are mostly meant to be used for configuring the Docker containers. They allow to specify the base Node.js and MySQL Docker images, the network proxy setup, and the URL of the NPM registry to use.
8991

9092
* `BASE_IMAGE` (`container-registry.oracle.com/graalvm/nodejs:latest` by default)
9193
* `HTTP_PROXY` (value of the environment variable in the host by default)
9294
* `HTTPS_PROXY` (value of the environment variable in the host by default)
95+
* `MYSQL_IMAGE` (`mysql/mysql-server` by default)
96+
* `MYSQL_VERSION` (`latest` by default)
9397
* `NO_PROXY` (value of the environment variable in the host by default)
9498
* `NPM_REGISTRY` (`https://registry.npmjs.org/` by default)
9599

@@ -98,7 +102,7 @@ There is one additional environment variable called `TEST_PATTERN` which can be
98102
Ultimately, the script allows an argument which identifies the underlying NPM script that gets executed. So, in theory, any of the available NPM scripts can be executed in the container, but by default, it will execute the `test` script.
99103

100104
```sh
101-
# executing the default test script with the default environment (Linux only)
105+
# executing the default test script with the default environment
102106
$ ./test/docker/run.sh
103107
# executing the unit test suite
104108
$ ./test/docker/run.sh test:unit
@@ -108,7 +112,18 @@ $ MYSQLX_HOST='<hostname_or_IP_address>' TEST_PATTERN='using CRUD' ./test/docker
108112
$ MYSQLX_SOCKET='/path/to/socket' ./test/docker/run.sh test:functional
109113
```
110114

111-
Similar to when the tests run on a local environment, the `MYSQLX_HOST` variable is only relevant for the functional tests. On Linux, the variable is optional and the Docker container will run using the "host" network mode whilst tests assume the MySQL server is listening on `localhost`. On macOS, since containers run on a virtual machine, host loopback addresses are not reachable. In that case, the `MYSQLX_HOST` variable is required and should specify the hostname or IP address of the MySQL server.
115+
Users are still able to run the default functional test suite using their own MySQL server instance. Similar to when the tests run on a local environment, the `MYSQLX_HOST` variable is only relevant for the functional tests. The variable is optional and the tests running in the Docker container assume the MySQL server is listening on the host machine and is reachable via `host.docker.internal`. If the MySQL server instance is not running in the host machine, the `MYSQLX_HOST` variable can specify the appropriate hostname or IP address. There is a fallback server instance running in one of the Docker containers which is reachable via `mysql.docker.internal`.
116+
117+
```sh
118+
# executing the extended functional tests in the Docker environment
119+
$ ./test/docker/run.sh test:functional:extended
120+
# executing the default functional tests in the Docker environment
121+
$ MYSQLX_HOST='mysql.docker.internal' ./test/docker/run.sh test:functional
122+
# executing the default functional tests with a local MySQL server instance and the extended tests in the Docker environment
123+
$ ./test/docker/run.sh test:functional:all
124+
# executing all tests in the Docker environment
125+
$ MYSQLX_HOST='mysql.docker.internal' ./test/docker/run.sh test:all
126+
```
112127

113128
Due to some [know limitations](https://github.com/docker/for-mac/issues/483) on the macOS Docker architecture, Unix socket tests can only run on Linux. In that case, if the `MYSQLX_SOCKET` variable is explicitely specified, a shared volume between the host and the container will be created as a mount point from the socket file path in the host and an internal container directory specified as a volume, where the socket file path becomes available.
114129

@@ -131,6 +146,23 @@ As a formal rule, a patch should not lead to a decrease of the overall code cove
131146

132147
Besides looking at the content generated via the standard output of your command line, you can also check the report available at `coverage/index.html` using a web browser.
133148

149+
Code coverage reports can also be generated in the Docker environment using the same set of NPM scripts.
150+
151+
```sh
152+
# generate code coverage reports using the default test suite
153+
$ ./test/docker/run.sh coverage
154+
# generate code coverage reports using the unit test suite
155+
$ ./test/docker/run.sh coverage:unit
156+
# generate code coverage reports using the default functional test suite
157+
$ ./test/docker/run.sh coverage:functional
158+
# generate code coverage reports using the extended functional test suite
159+
$ ./test/docker/run.sh coverage:functional:extended
160+
# generate code coverage reports using the full test suite
161+
$ ./test/docker/run.sh coverage:functional:all
162+
```
163+
164+
A `coverage` folder will be created in the project root directory containing the artifacts generated by the container, which are copied using a bind mount. If the folder already exists, the contents will be replaced.
165+
134166
### Code Style and Convention
135167

136168
Any change to the project's source code must also follow the standard set of code style/convention rules enforced by the existing tooling infrastructure. So, before submitting a patch, you can check if it violates any of those rules using the following:

lib/tool/test.js

Lines changed: 0 additions & 83 deletions
This file was deleted.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,22 @@
4747
"scripts": {
4848
"coverage": "nyc npm run test",
4949
"coverage:functional": "nyc npm run test:functional",
50+
"coverage:functional:all": "nyc npm run test:functional:all",
51+
"coverage:functional:extended": "nyc npm run test:functional:extended",
5052
"coverage:summary": "nyc report --reporter=text-summary",
5153
"coverage:unit": "nyc npm run test:unit",
5254
"fix:lib": "standardx --fix",
5355
"fix:types": "eslint --fix -c types/.eslintrc.js .",
5456
"lint:lib": "standardx --verbose | snazzy",
5557
"lint:types": "eslint -c types/.eslintrc.js .",
5658
"lint": "npm run lint:lib && npm run lint:types",
57-
"mocha": "mocha --reporter spec --timeout 10000 --recursive",
59+
"mocha": "mocha --reporter spec --timeout 30000 --recursive",
5860
"prepack": "node bin/prepack.js",
5961
"test": "tsd && npm run mocha test/unit test/functional/default",
62+
"test:all": "tsd && npm run mocha test/unit test/functional",
6063
"test:functional": "npm run mocha test/functional/default",
64+
"test:functional:all": "npm mocha test/functional",
65+
"test:functional:extended": "npm run mocha test/functional/extended",
6166
"test:unit": "npm run mocha test/unit",
6267
"test:types": "tsd"
6368
},

test/config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2015, 2023, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License, version 2.0, as
@@ -35,7 +35,6 @@ module.exports = {
3535
password: process.env.MYSQLX_PASSWORD || '',
3636
port: parseInt(process.env.MYSQLX_PORT, 10) || 33060,
3737
schema: process.env.MYSQLX_DEFAULT_SCHEMA,
38-
socket: process.env.MYSQLX_SOCKET,
3938
tls: { enabled: process.env.MYSQLX_TLS !== 'false' },
4039
user: process.env.MYSQLX_USER || 'root'
4140
};

test/docker/docker-compose.Darwin.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2023, Oracle and/or its affiliates.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License, version 2.0, as
5+
# published by the Free Software Foundation.
6+
#
7+
# This program is also distributed with certain software (including
8+
# but not limited to OpenSSL) that is licensed under separate terms,
9+
# as designated in a particular file or component or in included license
10+
# documentation. The authors of MySQL hereby grant you an
11+
# additional permission to link the program and your derivative works
12+
# with the separately licensed software that they have included with
13+
# MySQL.
14+
#
15+
# Without limiting anything contained in the foregoing, this file,
16+
# which is part of MySQL Connector/Node.js, is also subject to the
17+
# Universal FOSS Exception, version 1.0, a copy of which can be found at
18+
# http://oss.oracle.com/licenses/universal-foss-exception.
19+
#
20+
# This program is distributed in the hope that it will be useful, but
21+
# WITHOUT ANY WARRANTY; without even the implied warranty of
22+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23+
# See the GNU General Public License, version 2.0, for more details.
24+
#
25+
# You should have received a copy of the GNU General Public License
26+
# along with this program; if not, write to the Free Software Foundation, Inc.,
27+
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28+
29+
services:
30+
mysql-connector-nodejs:
31+
extra_hosts: []

test/docker/docker-compose.Linux.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2023, Oracle and/or its affiliates.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License, version 2.0, as
5+
# published by the Free Software Foundation.
6+
#
7+
# This program is also distributed with certain software (including
8+
# but not limited to OpenSSL) that is licensed under separate terms,
9+
# as designated in a particular file or component or in included license
10+
# documentation. The authors of MySQL hereby grant you an
11+
# additional permission to link the program and your derivative works
12+
# with the separately licensed software that they have included with
13+
# MySQL.
14+
#
15+
# Without limiting anything contained in the foregoing, this file,
16+
# which is part of MySQL Connector/Node.js, is also subject to the
17+
# Universal FOSS Exception, version 1.0, a copy of which can be found at
18+
# http://oss.oracle.com/licenses/universal-foss-exception.
19+
#
20+
# This program is distributed in the hope that it will be useful, but
21+
# WITHOUT ANY WARRANTY; without even the implied warranty of
22+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23+
# See the GNU General Public License, version 2.0, for more details.
24+
#
25+
# You should have received a copy of the GNU General Public License
26+
# along with this program; if not, write to the Free Software Foundation, Inc.,
27+
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28+
29+
services:
30+
mysql-connector-nodejs:
31+
extra_hosts:
32+
- "host.docker.internal:host-gateway"

test/docker/docker-compose.local.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) 2023, Oracle and/or its affiliates.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License, version 2.0, as
5+
# published by the Free Software Foundation.
6+
#
7+
# This program is also distributed with certain software (including
8+
# but not limited to OpenSSL) that is licensed under separate terms,
9+
# as designated in a particular file or component or in included license
10+
# documentation. The authors of MySQL hereby grant you an
11+
# additional permission to link the program and your derivative works
12+
# with the separately licensed software that they have included with
13+
# MySQL.
14+
#
15+
# Without limiting anything contained in the foregoing, this file,
16+
# which is part of MySQL Connector/Node.js, is also subject to the
17+
# Universal FOSS Exception, version 1.0, a copy of which can be found at
18+
# http://oss.oracle.com/licenses/universal-foss-exception.
19+
#
20+
# This program is distributed in the hope that it will be useful, but
21+
# WITHOUT ANY WARRANTY; without even the implied warranty of
22+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23+
# See the GNU General Public License, version 2.0, for more details.
24+
#
25+
# You should have received a copy of the GNU General Public License
26+
# along with this program; if not, write to the Free Software Foundation, Inc.,
27+
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28+
29+
services:
30+
mysql-connector-nodejs:
31+
volumes:
32+
# The test script ensures this configuration is only applied when the
33+
# $MYSQLX_SOCKET environment variable is specified.
34+
# In that case, it means the tests should use a Unix socket local to the
35+
# host machine, which needs to be copied to the container via a bind
36+
# mount.
37+
- ${MYSQLX_SOCKET}:${MYSQLX_SOCKET}:ro

0 commit comments

Comments
 (0)