Skip to content

Commit c7010fa

Browse files
change X init failure test to use http server port instead of mysql port
1 parent 0e4d756 commit c7010fa

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/libraries/Executor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ class Executor {
9595
if (options.xEnabled !== 'OFF') {
9696
mysqlArguments.push(`--mysqlx-port=${mySQLXPort}`)
9797
mysqlArguments.push(`--mysqlx-socket=${xSocket}`)
98-
mysqlArguments.push(`--mysqlx-bind-address=127.0.0.1`)
9998

10099
//<8.0.11 does not have MySQL X turned on by default so we will be installing the X Plugin in this if statement.
101100
//MySQL 5.7.12 introduced the X plugin, but according to https://dev.mysql.com/doc/refman/5.7/en/document-store-setting-up.html, the database needs to be initialised with version 5.7.19.

tests/ci/x.test.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {expect, test, jest} from '@jest/globals'
22
import { createDB } from '../../src/index'
33
import sql from 'mysql2/promise'
44
import { ServerOptions } from '../../types';
5+
import http from 'http';
56

67
jest.setTimeout(500_000); //5 minutes
78

@@ -88,11 +89,25 @@ test(`MySQL X is on when force enabling it`, async () => {
8889
})
8990

9091
test('DB creation throws when MySQL fails to initialise and X is force enabled', async () => {
92+
const server: http.Server = await new Promise(resolve => {
93+
const httpServer = new http.Server();
94+
httpServer.listen(0, () => {
95+
resolve(httpServer)
96+
})
97+
})
98+
99+
const serverAddress = server.address();
100+
if (typeof serverAddress === 'string') {
101+
throw 'serverAddress is a string. Should be an object'
102+
}
103+
if (serverAddress === null) {
104+
throw 'serverAddress is null. Should be an object.'
105+
}
106+
91107
const options: ServerOptions = {
92108
arch,
93109
logLevel: 'LOG',
94-
port: 3306,
95-
xPort: 3306,
110+
xPort: serverAddress.port, // Use a port that is already in use to get X to fail
96111
xEnabled: 'FORCE',
97112
initSQLString: 'SELECT 2+2;'
98113
}
@@ -105,5 +120,10 @@ test('DB creation throws when MySQL fails to initialise and X is force enabled',
105120
thrown = e
106121
}
107122

123+
await new Promise(resolve => {
124+
server.on('close', resolve)
125+
server.close()
126+
})
127+
108128
expect(thrown).toBe('The port has been retried 10 times and a free port could not be found.\nEither try again, or if this is a common issue, increase options.portRetries.')
109129
})

0 commit comments

Comments
 (0)