twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

multiple-conn.js (2057B)


      1 var assert = require('assert');
      2 
      3 var Twit = require('../lib/twitter');
      4 var config1 = require('../config1');
      5 var colors = require('colors');
      6 var restTest = require('./rest.js');
      7 
      8 /*
      9   Don't run these tests often otherwise Twitter will rate limit you
     10  */
     11 
     12 describe.skip('multiple connections', function () {
     13   it('results in one of the streams closing', function (done) {
     14     var twit = new Twit(config1);
     15 
     16     var streams = [
     17       twit.stream('statuses/sample'),
     18       twit.stream('statuses/sample'),
     19       twit.stream('statuses/sample'),
     20     ];
     21 
     22     streams.forEach(function (stream, i) {
     23       stream.on('disconnect', function (disconnect) {
     24         console.log('Disconect for stream', i)
     25         assert.equal(typeof disconnect, 'object');
     26         done();
     27       });
     28 
     29       stream.on('error', function (errMsg) {
     30         console.log('error for stream', i, errMsg)
     31       })
     32 
     33       stream.on('tweet', function (t) {
     34         console.log(i)
     35       })
     36 
     37       stream.on('connected', function () {
     38         console.log('Stream', i, 'connected.')
     39       })
     40     });
     41 
     42   });
     43 });
     44 
     45 describe.skip('Managing multiple streams legally', function () {
     46   this.timeout(60000);
     47   it('updating track keywords without losing data', function (done) {
     48     var twit = new Twit(config1);
     49     var stream1 = twit.stream('statuses/filter', { track: ['#no'] });
     50 
     51     stream1.once('tweet', function (tweet) {
     52       console.log('got tweet from first stream')
     53       restTest.checkTweet(tweet);
     54       restTest.assertTweetHasText(tweet, '#no');
     55 
     56       // update our track list and initiate a new connection
     57       var stream2 = twit.stream('statuses/filter', { track: ['#fun'] });
     58 
     59       stream2.once('connected', function (res) {
     60         console.log('second stream connected')
     61         // stop the first stream immediately
     62         stream1.stop();
     63         assert.equal(res.statusCode, 200)
     64 
     65         stream2.once('tweet', function (tweet) {
     66           restTest.checkTweet(tweet);
     67 
     68           restTest.assertTweetHasText(tweet, '#fun');
     69           return done();
     70         })
     71       });
     72     });
     73   });
     74 });