Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server.close() does not work?? #99

Open
Foxhoundn opened this issue Sep 5, 2016 · 8 comments
Open

server.close() does not work?? #99

Foxhoundn opened this issue Sep 5, 2016 · 8 comments

Comments

@Foxhoundn
Copy link

Foxhoundn commented Sep 5, 2016

describe.only('Websockets store handlers', () => {
  let store;

  beforeEach(() => {
    store = createStore(ws,
      applyMiddleware(
        thunk,
        promise,
      )
    );
  });

  it('connects the websocket', () => {
    const server = new Server('ws://qorus.example.com/log/main');

    store.subscribe(() => {
      const { data } = store.getState();

      expect(data).to.eql({
        'log/main': {
          loading: true,
          connected: false,
          error: false,
          paused: false,
        },
      });
    });

    store.dispatch(actions.connect('log/main'));

    server.close();
  });

  it('disconnects the websocket', () => {
    const server = new Server('ws://qorus.example.com/log/main');

    store.dispatch(actions.connect('log/main'));
    store.subscribe(() => {
      const { data } = store.getState();

      expect(data).to.eql({
        'log/main': {
          loading: false,
          connected: false,
          error: false,
          paused: false,
        },
      });
    });
    store.dispatch(actions.disconnect('log/main'));

    server.close();
  });
});
  1. Websockets store handlers disconnects the websocket:
    Error: A mock server is already listening on this url
@Foxhoundn
Copy link
Author

Sorry, It's actually server.stop(), but that doesn't really matter since that one does not work either :)

@thoov
Copy link
Owner

thoov commented Sep 6, 2016

@Foxhoundn Thanks for finding this. Let me dig into it and see what is happening

@thoov
Copy link
Owner

thoov commented Sep 6, 2016

Because I don't have access to your store/actions its going to be hard for me to debug. Are you able to create a simpler example of this bug without hitting a store?

@Chalisi
Copy link

Chalisi commented Jan 11, 2019

In the meantime I found that force a new connection avoid this issue. But if one test fail all the following tests will trigger this Error: A mock server is already listening on this url error.

new Server('socketioserverurl', {
     forceNew: true,
     reconnection: false
})

Is it possible that the problem is due to reconnection activated by default?

@tuzmusic
Copy link

tuzmusic commented Dec 3, 2019

I'm having a similar "already listening" problem, and I tried

new Server('socketioserverurl', {
     forceNew: true,
     reconnection: false
})

and first typescript said those weren't valid keys, and when I @ts-ignore that error, I still have the same 'already listening' problem.

@spacehash
Copy link

I'm also getting this error when I attempt multiple vitest cases, both concurrent and non-concurrent

@Atrue
Copy link
Collaborator

Atrue commented Nov 8, 2022

@spacehash Can you please provide a minimal reproducible test case?

@dhulme
Copy link

dhulme commented May 15, 2023

In my case it was a sign of a bug in my code/test which was causing it not to reach the close call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants