Skip to content

Commit f939119

Browse files
committed
tests: decouple fake server from MYSQL_HOST
Fake servers are being created on the host specified by the MYSQL_HOST environment variable. This can lead to issues when the real MySQL server instance used for the integration tests is not running on the same host, for instance, in Docker-based CI environments. This patch ensures fake servers are explicitely created in the host/container where the test suite is running.
1 parent 07a429d commit f939119

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

test/integration/connection/test-disconnects.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// This file was modified by Oracle on January 21, 2021.
2+
// The connection with the mock server needs to happen in the same host where
3+
// the tests are running in order to avoid connecting a potential MySQL server
4+
// instance running in the host identified by the MYSQL_HOST environment
5+
// variable.
6+
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
7+
18
'use strict';
29

310
const common = require('../../common');
@@ -10,7 +17,14 @@ const connections = [];
1017

1118
const server = common.createServer(
1219
() => {
13-
const connection = common.createConnection({ port: server._port });
20+
const connection = common.createConnection({
21+
// The mock server is running on the same host machine.
22+
// We need to explicitly define the host to avoid connecting to a potential
23+
// different host provided via MYSQL_HOST that identifies a real MySQL
24+
// server instance.
25+
host: 'localhost',
26+
port: server._port
27+
});
1428
connection.query('SELECT 123', (err, _rows, _fields) => {
1529
if (err) {
1630
throw err;

test/integration/connection/test-protocol-errors.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// This file was modified by Oracle on January 21, 2021.
2+
// The connection with the mock server needs to happen in the same host where
3+
// the tests are running in order to avoid connecting a potential MySQL server
4+
// instance running in the host identified by the MYSQL_HOST environment
5+
// variable.
6+
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
7+
18
'use strict';
29

310
const assert = require('assert');
@@ -9,7 +16,14 @@ let rows;
916

1017
const server = common.createServer(
1118
() => {
12-
const connection = common.createConnection({ port: server._port });
19+
const connection = common.createConnection({
20+
// The mock server is running on the same host machine.
21+
// We need to explicitly define the host to avoid connecting to a potential
22+
// different host provided via MYSQL_HOST that identifies a real MySQL
23+
// server instance.
24+
host: 'localhost',
25+
port: server._port
26+
});
1327
connection.query(query, (err, _rows, _fields) => {
1428
if (err) {
1529
throw err;

test/integration/connection/test-quit.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// This file was modified by Oracle on January 21, 2021.
2+
// The connection with the mock server needs to happen in the same host where
3+
// the tests are running in order to avoid connecting a potential MySQL server
4+
// instance running in the host identified by the MYSQL_HOST environment
5+
// variable.
6+
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
7+
18
'use strict';
29

310
const assert = require('assert');
@@ -9,7 +16,14 @@ let rows;
916
let fields;
1017
const server = common.createServer(
1118
() => {
12-
const connection = common.createConnection({ port: server._port });
19+
const connection = common.createConnection({
20+
// The mock server is running on the same host machine.
21+
// We need to explicitly define the host to avoid connecting to a potential
22+
// different host provided via MYSQL_HOST that identifies a real MySQL
23+
// server instance.
24+
host: 'localhost',
25+
port: server._port
26+
});
1327

1428
connection.query(queryCli, (err, _rows, _fields) => {
1529
if (err) {

test/integration/connection/test-stream-errors.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// This file was modified by Oracle on January 21, 2021.
2+
// The connection with the mock server needs to happen in the same host where
3+
// the tests are running in order to avoid connecting a potential MySQL server
4+
// instance running in the host identified by the MYSQL_HOST environment
5+
// variable.
6+
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
7+
18
'use strict';
29

310
const assert = require('assert');
@@ -12,7 +19,14 @@ const query = 'SELECT 1';
1219

1320
const server = common.createServer(
1421
() => {
15-
clientConnection = common.createConnection({ port: server._port });
22+
clientConnection = common.createConnection({
23+
// The mock server is running on the same host machine.
24+
// We need to explicitly define the host to avoid connecting to a potential
25+
// different host provided via MYSQL_HOST that identifies a real MySQL
26+
// server instance.
27+
host: 'localhost',
28+
port: server._port
29+
});
1630
clientConnection.query(query, err => {
1731
receivedError1 = err;
1832
});

0 commit comments

Comments
 (0)