From d1ba61978813ed65f8e3a26af2fa43300a2e1e06 Mon Sep 17 00:00:00 2001 From: extremeheat Date: Wed, 10 Aug 2022 13:29:46 -0400 Subject: [PATCH] Fix proxy test waiting condition (#250) * Fix proxy test waiting condition * update test command * Update proxy.js * Update proxy.js * Update proxy.js --- package.json | 2 +- test/proxy.js | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index d29f497..ac756e1 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "build": "cd tools && node compileProtocol.js", - "test": "mocha --bail", + "test": "mocha --bail --exit", "pretest": "npm run lint", "lint": "standard", "vanillaServer": "node tools/startVanillaServer.js", diff --git a/test/proxy.js b/test/proxy.js index a69b93c..a1df25e 100644 --- a/test/proxy.js +++ b/test/proxy.js @@ -1,18 +1,19 @@ -const { createClient, createServer, Relay } = require('bedrock-protocol') +const { createClient, Server, Relay } = require('bedrock-protocol') const { sleep, waitFor } = require('../src/datatypes/util') function proxyTest (version, raknetBackend = 'raknet-node', timeout = 1000 * 40) { console.log('with raknet backend', raknetBackend) - return waitFor(res => { + return waitFor(async res => { const SERVER_PORT = 19000 + ((Math.random() * 100) | 0) const CLIENT_PORT = 19000 + ((Math.random() * 100) | 0) - const server = createServer({ + const server = new Server({ host: '0.0.0.0', // optional port: SERVER_PORT, // optional offline: true, raknetBackend, version // The server version }) + await server.listen() server.on('connect', client => { console.debug('Client has connected') @@ -40,16 +41,14 @@ function proxyTest (version, raknetBackend = 'raknet-node', timeout = 1000 * 40) raknetBackend }) relay.conLog = console.debug - relay.listen() + await relay.listen() console.debug('Proxy started', server.options.version) - const client = createClient({ host: '127.0.0.1', port: CLIENT_PORT, version, username: 'Boat', offline: true, raknetBackend }) - + const client = createClient({ host: '127.0.0.1', port: CLIENT_PORT, version, username: 'Boat', offline: true, raknetBackend, skipPing: true }) console.debug('Client started') - + client.on('error', console.log) client.on('packet', console.log) - client.on('disconnect', packet => { console.assert(packet.message === 'Hello world !')