stomp-js / ng2-stompjs

Angular 6 and 7 - Stomp service over Websockets
https://stomp-js.github.io/
Apache License 2.0
182 stars 32 forks source link

Protractor and Stomp #133

Open BillSheldon-HunterIndustries opened 5 years ago

BillSheldon-HunterIndustries commented 5 years ago

We are working with the latest release of both Angular 7 and Stomp 7.2.0. We ran into a conflict with our existing protractor tests when we upgraded from StompRService and StompConfig to RxStompService and RxStompConfig. Injecting the RxStompService into the constructor breaks the existing protractor test with the below error

`

We created a new CLI project to reproduce the issue. As part of working with this solution we found that adding browser.waitForAngularEnabled(false); enabled a given test to run successfully.

Unfortunately, in our existing project, we have hundreds of tests and this workaround will not work in most instances. Since we monitor the RabbitMQ queues at the application level, we would be interested in any suggestions or a solution that allowed us to bypass this issue for our protractor tests.

Thanks Bill & the Hunter Industries Pilot Mob

kum-deepak commented 5 years ago

I must be honest - I have not written a single protractor test myself :smile:

You have mentioned that when you used StompRService and StompConfig it used to work. Can you please check which version of @stomp/ng2-stompjs and @stomp/stompjs were in use.

Meanwhile, I will also get a shot at writing some protractor tests.

BillSheldon-HunterIndustries commented 5 years ago

Hi Deepak,

We are using version 7.2.0 of @stomp/ng2-stompjs. We tried the e2e example that was provided in your source code (ng2-stompjs-angular7) and were able to reproduce the issue. We think it's an issue of the stomp continuously connecting to the website/queue and not giving control back to protractor. We believe that is why adding browser.waitForAngularEnabled(false) works, as it enables protractor to continue execution without angular to finish all requests.

Thank you, Bill & the Hunter Industries Pilot Mob

mstawick commented 3 years ago

This seems to have worked for me (socket gets created outside angular):

export function rxStompOutsideAngularServiceFactory(rxStompConfig: InjectableRxStompConfig, ngZone: NgZone): RxStompService {
  return ngZone.runOutsideAngular(() => {
    return rxStompServiceFactory(rxStompConfig);
  });
}

and then:

{provide: RxStompService, useFactory: rxStompOutsideAngularServiceFactory, deps: [InjectableRxStompConfig, NgZone]},

Just remember that you'll need to get back to angular zone inside stomp callbacks (if needed of course). For my project, it was fairly easy, because I've already had wrappers for watch/rpc.

kum-deepak commented 3 years ago

Wow! This is good news. Thanks! I am changing the label.

kum-deepak commented 3 years ago

Will you be able to fork https://github.com/stomp-js/ng2-stompjs-angular7 and update it to write one simple test. If you prefer you can use the angular10 branch.