Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Polling with $timeout prevents scenario step from completing #2402

Closed
karlgoldstein opened this issue Apr 14, 2013 · 4 comments
Closed

Polling with $timeout prevents scenario step from completing #2402

karlgoldstein opened this issue Apr 14, 2013 · 4 comments

Comments

@karlgoldstein
Copy link

If you use $timeout to perform any operation on a set interval in your application, then the 'browseTo' step never completes.

Minimal demonstration here:

http://plnkr.co/edit/iW3dHM?p=preview

Note that the test application is not hung in the scenario runner iframe, it's just that browseTo never completes.

Problem seems to be with the way that the scenario runner tries to make sure that all async operations are complete before advancing to the next step. outstandingRequestCount never decrements to zero because the $timeout callback reschedules itself.

@pa3zo6
Copy link

pa3zo6 commented Apr 19, 2013

+1
Any workaround?

@karlgoldstein
Copy link
Author

My workaround was to create an 'interval' service that I can disable using a query parameter when the application loads:

module = angular.module 'fl.interval', ['fl.env']

module.service 'interval', ['$timeout', 'environment', ($timeout, environment) ->

  tasks = []

  poll = ->
    for task in tasks
      elapsed = Math.ceil(Date.now() / 1000) - task.start
      if elapsed > 0 && elapsed % task.seconds == 0
        task.job()
    $timeout poll, 1000
    return null

  poll() if environment.interactive

  schedule: (job, seconds) ->
    tasks.push
      job: job
      seconds: seconds
      start: Math.ceil(Date.now() / 1000)
]

It's actually kind of nice to have this wrapped in a service, instead of having the polling setup mixed in with other code.

'environment' is just a 'constant' (in angular terms) that I have for global config. I do this in a run block at startup:

interactive = $location.search().interactive
environment.interactive = false if interactive == 'false'

when I call browseTo to start a scenario, I add ?interactive=false to the path

@lucassus
Copy link

lucassus commented Jul 4, 2013

@pa3zo6 you could find some ideas in this commit lucassus/angular-coffee-seed@445f55c

juliemr added a commit to juliemr/angular.js that referenced this issue Oct 7, 2013
The $interval service simplifies creating and testing recurring tasks.
This service does not increment $browser's outstanding request count,
which means that scenario tests and Protractor tests will not timeout
when a site uses a polling function registered by $interval. Provides
a workaround for angular#2402.

For unit tests, repeated tasks can be controlled using ngMock$interval's
tick(), tickNext(), and tickAll() functions.
vojtajina pushed a commit to vojtajina/angular.js that referenced this issue Oct 7, 2013
The $interval service simplifies creating and testing recurring tasks.
This service does not increment $browser's outstanding request count,
which means that scenario tests and Protractor tests will not timeout
when a site uses a polling function registered by $interval. Provides
a workaround for angular#2402.

For unit tests, repeated tasks can be controlled using ngMock$interval's
tick(), tickNext(), and tickAll() functions.
@petebacondarwin
Copy link
Contributor

Should be fixed by $interval service

jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
The $interval service simplifies creating and testing recurring tasks.
This service does not increment $browser's outstanding request count,
which means that scenario tests and Protractor tests will not timeout
when a site uses a polling function registered by $interval. Provides
a workaround for angular#2402.

For unit tests, repeated tasks can be controlled using ngMock$interval's
tick(), tickNext(), and tickAll() functions.
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
The $interval service simplifies creating and testing recurring tasks.
This service does not increment $browser's outstanding request count,
which means that scenario tests and Protractor tests will not timeout
when a site uses a polling function registered by $interval. Provides
a workaround for angular#2402.

For unit tests, repeated tasks can be controlled using ngMock$interval's
tick(), tickNext(), and tickAll() functions.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants