Giter Site home page Giter Site logo

can not auto-reconnect about veza HOT 2 OPEN

kyranet avatar kyranet commented on September 29, 2024
can not auto-reconnect

from veza.

Comments (2)

kyranet avatar kyranet commented on September 29, 2024

It's possible the behaviour of Node.js's net module changed with v13, I'll have to check, and while I'm at it, check why Dependabot's PRs are red.

But yes, your expected behaviour is also the one I expected, I believe I have a test just for that:

veza/test/handshake.test.ts

Lines 240 to 294 in 82a5765

test('Socket Connection Retries (Successful Reconnect)', { timeout: 7500 }, async t => {
t.plan(4);
const [nodeServer, nodeSocket] = await setup(t, ++port, { maximumRetries: 3, retryTime: 200 });
await nodeServer.close();
nodeSocket.once('connecting', () => {
t.pass('Reconnecting event fired.');
next();
});
async function next() {
nodeSocket
.once('connect', () => t.pass('Socket fired connect'))
.once('ready', () => t.pass('Socket fired Ready'));
await nodeServer.listen(port);
await new Promise(resolve => {
nodeServer.once('connect', resolve);
});
t.pass('Successfully reconnected the server.');
await nodeServer.close();
nodeSocket.disconnectFrom('Server');
}
});
test('Socket Connection Retries (Successful Reconnect | Different Name)', { timeout: 7500 }, async t => {
t.plan(8);
const [nodeServerFirst, nodeSocket] = await setup(t, ++port, { maximumRetries: 3, retryTime: 200 });
const socketServer = nodeSocket.get('Server')!;
t.equal(socketServer.name, 'Server', 'The Server should be "Server".');
// Disconnect and set up a second server with a different name
await nodeServerFirst.close();
const nodeServerSecond = new Server('NewServer');
nodeSocket.once('connecting', async () => {
t.pass('Reconnecting event fired.');
nodeSocket
.once('connect', () => t.pass('Socket fired connect'))
.once('ready', () => t.pass('Socket fired Ready'));
await nodeServerSecond.listen(port);
await new Promise(resolve => {
nodeServerSecond.once('connect', resolve);
});
t.pass('Successfully reconnected the server.');
t.equal(nodeSocket.get('Server'), null, 'Since the name of the server has changed, the key "Server" should be null.');
t.equal(nodeSocket.get('NewServer'), socketServer, 'The socket should be available under the key "NewServer".');
t.equal(socketServer.name, 'NewServer', 'The name for the socket should be changed to "NewServer".');
await nodeServerSecond.close();
nodeSocket.disconnectFrom('NewServer');
});
});

Also, what happens if you only pass a port to connectTo and serve? server.listen(11122); and client.connectTo(11122); for instance.

from veza.

AaronJan avatar AaronJan commented on September 29, 2024

It's possible the behaviour of Node.js's net module changed with v13, I'll have to check, and while I'm at it, check why Dependabot's PRs are red.

But yes, your expected behaviour is also the one I expected, I believe I have a test just for that:

veza/test/handshake.test.ts

Lines 240 to 294 in 82a5765

test('Socket Connection Retries (Successful Reconnect)', { timeout: 7500 }, async t => {
t.plan(4);
const [nodeServer, nodeSocket] = await setup(t, ++port, { maximumRetries: 3, retryTime: 200 });
await nodeServer.close();
nodeSocket.once('connecting', () => {
t.pass('Reconnecting event fired.');
next();
});
async function next() {
nodeSocket
.once('connect', () => t.pass('Socket fired connect'))
.once('ready', () => t.pass('Socket fired Ready'));
await nodeServer.listen(port);
await new Promise(resolve => {
nodeServer.once('connect', resolve);
});
t.pass('Successfully reconnected the server.');
await nodeServer.close();
nodeSocket.disconnectFrom('Server');
}
});
test('Socket Connection Retries (Successful Reconnect | Different Name)', { timeout: 7500 }, async t => {
t.plan(8);
const [nodeServerFirst, nodeSocket] = await setup(t, ++port, { maximumRetries: 3, retryTime: 200 });
const socketServer = nodeSocket.get('Server')!;
t.equal(socketServer.name, 'Server', 'The Server should be "Server".');
// Disconnect and set up a second server with a different name
await nodeServerFirst.close();
const nodeServerSecond = new Server('NewServer');
nodeSocket.once('connecting', async () => {
t.pass('Reconnecting event fired.');
nodeSocket
.once('connect', () => t.pass('Socket fired connect'))
.once('ready', () => t.pass('Socket fired Ready'));
await nodeServerSecond.listen(port);
await new Promise(resolve => {
nodeServerSecond.once('connect', resolve);
});
t.pass('Successfully reconnected the server.');
t.equal(nodeSocket.get('Server'), null, 'Since the name of the server has changed, the key "Server" should be null.');
t.equal(nodeSocket.get('NewServer'), socketServer, 'The socket should be available under the key "NewServer".');
t.equal(socketServer.name, 'NewServer', 'The name for the socket should be changed to "NewServer".');
await nodeServerSecond.close();
nodeSocket.disconnectFrom('NewServer');
});
});

Also, what happens if you only pass a port to connectTo and serve? server.listen(11122); and client.connectTo(11122); for instance.

Thank you for the quick reply!

I tested it by only pass a port to both server and client, it didn't work, still the same.

from veza.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.