E2E tests and $timeout = problem.

1,160 views
Skip to first unread message

Witold Szczerba

unread,
Jun 22, 2012, 7:52:33 PM6/22/12
to ang...@googlegroups.com
Hi there,
I have a problem testing my application. E2E test opens first page and
waits forever. I have figured out this is because my application
fetches data from server every 15 secs (it is looking for new tasks
for current user). The problem is E2E test waits for $timeout to
trigger (15 seconds delay) but once it triggers it schedules itself
again and again, so tests are waiting forever.

I have created a very simple example:
https://github.com/witoldsz/angular-testfield/tree/e2e-timeout-problem
this is the problematic part:
https://github.com/witoldsz/angular-testfield/blob/e2e-timeout-problem/app/js/controllers.js

It is a fork of angular-seed, so launch it the usual way:
execute: scripts/web-server.js
visit: http://localhost:8000/test/e2e/runner.html

What would you suggest to address this problem?
I have figured out, I can replace $timeout with plain old setTimeout +
scope.apply, so E2E runner would not be aware of the processing queue,
but isn't the whole idea of $timeout was to eliminate the setTimeouts
and scope's apply tandem?

Thanks,
Witold Szczerba

Vojta Jína

unread,
Jun 25, 2012, 5:00:42 PM6/25/12
to ang...@googlegroups.com
Hey Witold,

we are aware of this, although there is currently no nice solution for it.

We want people to use $timeout, because:
- it takes care of $apply
- it is considered by scenario runner

I'm thinking about:
- having setInterval support, that would be ignored by scenario runner (or it would have a special dsl for waiting number of intervals)
- allow some $timeouts to be ignored by the runner (this happens in $browser, outstandingRequestCount)

I think longer term solution is to get rid off $browser.outstandingRequestCount and rather have scenario runner to hook into angular app, by injecting it's own $timeout service or something like that.

In meantime, your solution with setTimeout will definitely work.


V.


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.


Witold Szczerba

unread,
Jun 25, 2012, 5:37:19 PM6/25/12
to ang...@googlegroups.com
Thanks Vojta.
I think, for now, maybe I will create my own $timeout service, it will
use setTimeout with scope#apply under the hood.

Regards,
Witold Szczerba
Message has been deleted

Jonathan Meiss

unread,
Dec 5, 2012, 9:49:00 AM12/5/12
to ang...@googlegroups.com
Hi guys!

Is there any news about it?

I'm doing long polling via $timeout to display new notification messages in my application but when I run my e2e tests it blocks at the first test
and nothing displayed in the console. I know that $timeout is guilty because when I comment it, my tests runs.

Is there a nicest solution than create my own $timeout service like Witold?

Regards,
John (from DotJS ;) ) 

Jonathan Meiss

unread,
Dec 10, 2012, 4:32:56 AM12/10/12
to ang...@googlegroups.com
So nobody using $timeout write e2e tests??

Witold Szczerba

unread,
Dec 10, 2012, 5:59:11 AM12/10/12
to ang...@googlegroups.com

Jonathan,
all you really need to do is to write your own 'pool' service, it is going to be like five lines long.
If you really hate the idea it is not officially part of AngularJS public API, then create pull request and focus on persuading ANG devs to pull it.

Regards,
Witold Szczerba
---
Sent from my mobile phone.

Jonathan Meiss

unread,
Dec 10, 2012, 7:43:04 AM12/10/12
to ang...@googlegroups.com
Thanks Witold, I'll do that ;)
Reply all
Reply to author
Forward
0 new messages