title: How to test applications that use long polling with Protractor
body: <p>I am building an Angular app that uses long polling to receive fast updates whenever something changes on the server. I use $resource like this to fetch the actual data:</p>
  
  <pre><code>appServices.factory('Data', ['$resource', 
    function(){
      return $resource('', {}, {
          query: {"url": …, isArray: false}
    });
  }]);
  </code></pre>
  
  <p>Then I have a service that takes care of the long polling: Wait that the data are loaded; store them somewhere; after one second, start the next long-polling cycle:</p>
  
  <pre><code>app.factory(„DataLoader“, [„Data“, "$timeout", function(Data, $timeout) {
      return {
              loadData: function() {
                  var parent = this;
                  var data = Data.query({},
                          function(result) {
                            /* do something to the data,
                             * then start waiting for an update from the server again
                             */
                             $timeout(function() {
                                  parent.loadData();
                             }, 1000);
                          }
                  );
              }
       };
  });
  </code></pre>
  
  <p>It works like a charm so far.</p>
  
  <p>However, I am now trying to write Protractor tests for this. The problem is: The server times out the long polling requests after 30 seconds only if there are no changes to the data. As I am waiting for new data inside $timeout, Protractor times out before any results arrive.</p>
  
  <p>I have googled the last hour, but there doesn't seem to be a solution except for using $interval instead of $timeout. This works in a good old polling setup (poll every 3 seconds, get empty results from the server if there's nothing new). However, to avoid exactly that, I implemented long polling. $timeout is just the much more sensible option for me.</p>
  
  <p>Can you give me any tips how to get Protractor running successfully in this environment?</p>