ng2-stompjs icon indicating copy to clipboard operation
ng2-stompjs copied to clipboard

Protractor and Stomp

Open BillSheldon-HunterIndustries opened this issue 6 years ago • 5 comments

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

`

  • Failed: script timeout: result was not received in 11 seconds (Session info: chrome=71.0.3578.98) (Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.17134 x86_64) `

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

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.

kum-deepak avatar Feb 15 '19 12:02 kum-deepak

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

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.

mstawick avatar Jan 07 '21 18:01 mstawick

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

kum-deepak avatar Jan 08 '21 14:01 kum-deepak

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.

kum-deepak avatar Jan 08 '21 14:01 kum-deepak