Skip to content

Commit

Permalink
fix: when port is pased as a string convert it to a number (Bun's net…
Browse files Browse the repository at this point in the history
….connect does not automatically convert this)
  • Loading branch information
sidorares committed Jan 30, 2023
1 parent 8389bfe commit 703ecb2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/ci-bun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jobs:
with:
bun-version: ${{ matrix.bun-version }}

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Cache dependencies
uses: actions/cache@v3
with:
Expand All @@ -45,10 +49,14 @@ jobs:
restore-keys: npm-

- name: Install npm dependencies
run: bun install
run: npm ci

# - name: Install npm dependencies
# run: bun install

- name: Wait mysql server is ready
run: bun tools/wait-up.js
run: node tools/wait-up.js

- name: Run tests
# todo: run full test suite once test createServer is implemented using Bun.listen
run: MYSQL_PORT=3306 MYSQL_USE_TLS=${{ matrix.use-tls }} MYSQL_USE_COMPRESSION=${{ matrix.use-compression }} bun test/integration/connection/test-select-1.js
run: DEBUG=1 MYSQL_PORT=3306 bun test/integration/connection/test-select-1.js
1 change: 0 additions & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class Connection extends EventEmitter {
if (opts.config.socketPath) {
this.stream = Net.connect(opts.config.socketPath);
} else {
console.log('connecting to', opts.config.host, opts.config.port, typeof opts.config.port);
this.stream = Net.connect(
opts.config.port,
opts.config.host
Expand Down
4 changes: 2 additions & 2 deletions lib/connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ConnectionConfig {
this.isServer = options.isServer;
this.stream = options.stream;
this.host = options.host || 'localhost';
this.port = options.port || 3306;
this.port = (typeof options.port === 'string' ? parseInt(options.port, 10) : options.port)|| 3306;
this.localAddress = options.localAddress;
this.socketPath = options.socketPath;
this.user = options.user || undefined;
Expand Down Expand Up @@ -254,7 +254,7 @@ class ConnectionConfig {
const parsedUrl = new URL(url);
const options = {
host: parsedUrl.hostname,
port: parsedUrl.port,
port: parseInt(parsedUrl.port, 10),
database: parsedUrl.pathname.slice(1),
user: parsedUrl.username,
password: parsedUrl.password
Expand Down
2 changes: 1 addition & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ exports.config = config;
exports.waitDatabaseReady = function(callback) {
const start = Date.now();
const tryConnect = function() {
const conn = exports.createConnection({ database: 'mysql', password: process.env.MYSQL_PASSWORD ?? '' });
const conn = exports.createConnection({ database: 'mysql', password: process.env.MYSQL_PASSWORD });
conn.once('error', err => {
if (err.code !== 'PROTOCOL_CONNECTION_LOST' && err.code !== 'ETIMEDOUT') {
console.log('Unexpected error waiting for connection', err);
Expand Down
21 changes: 20 additions & 1 deletion test/integration/connection/test-select-1.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
'use strict';

console.log('Hello from bun test', typeof Bun);

const common = require('../../common');

console.log('after import');

const connection = common.createConnection();
const assert = require('assert');
connection.on('connect', function(hello) {
console.log('connect', hello.serverVersion, hello.protocolVersion);
})
console.log('after create connection');
//const assert = require('assert');
connection.query('SELECT 1', (err, _rows, _fields) => {
console.log('query callback', err, _rows, _fields);
connection.end();
console.log('after end connection');
});


/*
let rows = undefined;
let fields = undefined;
Expand All @@ -20,3 +37,5 @@ process.on('exit', () => {
assert.deepEqual(rows, [{ 1: 1 }]);
assert.equal(fields[0].name, '1');
});
*/

0 comments on commit 703ecb2

Please sign in to comment.