| 
									
										
										
										
											2018-10-13 14:47:42 -04:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var assert = require('assert'); | 
					
						
							|  |  |  | var nconf = require('nconf'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var db = require('./mocks/databasemock'); | 
					
						
							|  |  |  | var pubsub = require('../src/pubsub'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('pubsub', function () { | 
					
						
							| 
									
										
										
										
											2018-10-17 14:20:15 -04:00
										 |  |  | 	it('should use the plain event emitter', function (done) { | 
					
						
							| 
									
										
										
										
											2020-07-07 20:13:14 -04:00
										 |  |  | 		nconf.set('isCluster', false); | 
					
						
							| 
									
										
										
										
											2018-10-17 14:20:15 -04:00
										 |  |  | 		pubsub.reset(); | 
					
						
							| 
									
										
										
										
											2018-10-13 14:47:42 -04:00
										 |  |  | 		pubsub.on('testEvent', function (message) { | 
					
						
							|  |  |  | 			assert.equal(message.foo, 1); | 
					
						
							|  |  |  | 			pubsub.removeAllListeners('testEvent'); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		pubsub.publish('testEvent', { foo: 1 }); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-17 14:58:34 -04:00
										 |  |  | 	it('should use same event emitter', function (done) { | 
					
						
							|  |  |  | 		pubsub.on('dummyEvent', function (message) { | 
					
						
							|  |  |  | 			assert.equal(message.foo, 2); | 
					
						
							| 
									
										
										
										
											2020-07-07 20:13:14 -04:00
										 |  |  | 			nconf.set('isCluster', true); | 
					
						
							| 
									
										
										
										
											2018-10-17 14:58:34 -04:00
										 |  |  | 			pubsub.removeAllListeners('dummyEvent'); | 
					
						
							|  |  |  | 			pubsub.reset(); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		pubsub.publish('dummyEvent', { foo: 2 }); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-17 14:20:15 -04:00
										 |  |  | 	it('should use singleHostCluster', function (done) { | 
					
						
							| 
									
										
										
										
											2018-10-13 14:47:42 -04:00
										 |  |  | 		var oldValue = nconf.get('singleHostCluster'); | 
					
						
							| 
									
										
										
										
											2018-10-17 14:20:15 -04:00
										 |  |  | 		nconf.set('singleHostCluster', true); | 
					
						
							| 
									
										
										
										
											2018-10-13 14:47:42 -04:00
										 |  |  | 		pubsub.on('testEvent', function (message) { | 
					
						
							| 
									
										
										
										
											2018-10-17 14:58:34 -04:00
										 |  |  | 			assert.equal(message.foo, 3); | 
					
						
							| 
									
										
										
										
											2018-10-13 14:47:42 -04:00
										 |  |  | 			nconf.set('singleHostCluster', oldValue); | 
					
						
							|  |  |  | 			pubsub.removeAllListeners('testEvent'); | 
					
						
							| 
									
										
										
										
											2018-10-17 14:58:34 -04:00
										 |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		pubsub.publish('testEvent', { foo: 3 }); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should use same event emitter', function (done) { | 
					
						
							|  |  |  | 		var oldValue = nconf.get('singleHostCluster'); | 
					
						
							|  |  |  | 		pubsub.on('dummyEvent', function (message) { | 
					
						
							|  |  |  | 			assert.equal(message.foo, 4); | 
					
						
							|  |  |  | 			nconf.set('singleHostCluster', oldValue); | 
					
						
							|  |  |  | 			pubsub.removeAllListeners('dummyEvent'); | 
					
						
							| 
									
										
										
										
											2018-10-17 14:20:15 -04:00
										 |  |  | 			pubsub.reset(); | 
					
						
							| 
									
										
										
										
											2018-10-13 14:47:42 -04:00
										 |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-10-17 14:58:34 -04:00
										 |  |  | 		pubsub.publish('dummyEvent', { foo: 4 }); | 
					
						
							| 
									
										
										
										
											2018-10-13 14:47:42 -04:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }); |