Skip to content

Commit

Permalink
added a test to validate behaviour of concurrent eventSources
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofsajdak committed Jan 6, 2016
1 parent e2f6394 commit 67a33e4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/sse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,60 @@ describe('SSE', function () {
})
})
})

describe('When I start 10 eventSources and seed 1 book', function () {
it('Then all of the eventSources should receive the same book_i change event', function (done) {

const subject = new Rx.Subject()
const numberOfSources = 30

var eventSources = _.map(_.range(numberOfSources), ()=> {
const defer = Promise.defer()
const source = new EventSource(baseUrl + '/books/changes/streaming')

var eventStream = Rx.Observable.fromEvent(source, 'books_i')
.subscribe(subject)

Rx.Observable.fromEvent(source, 'open')
.do(()=> {
defer.resolve(source)
})
.subscribe(subject)
return defer.promise
});

Promise.all(eventSources)
.then((sources)=> {

subject
.bufferWithCount(numberOfSources)
.subscribe((events) => {
expect(events).to.have.length.of(numberOfSources)
_.each(events, (event)=> {
expect(_.omit(JSON.parse(event.data), 'id')).to.deep.equal(book)
})
_.map(sources, (source)=> {
source.close()
})
done()
});

const book = {
type: 'books',
attributes: {
title: 'test title 2'
}
};
seeder(server).dropCollectionsAndSeed({
books: [
book
]
})
})
}
)

})
})

describe('Multi resource', function () {
Expand Down

0 comments on commit 67a33e4

Please sign in to comment.