after(function(done) { //stop remote servers for(var i=0; i<gateways.length; i++) { gateways[i].stop(); } done(); });
describe('#rpcLogFilter', function () { it('should do after filter by before filter', function (done: MochaDone) { rpcLogFilter.before(mockData.serverId, mockData.msg, mockData.opts, function () { rpcLogFilter.after(mockData.serverId, mockData.msg, mockData.opts, function (serverId: number, msg: string, opts: any) { should.exist((mockData.opts as any)['__start_time__']); done(); }); }); }); });
it('should fail unbind session if session not exist', function (done: MochaDone) { let service = new SessionService(); let sid = 1; let uid = 'py'; service.unbind(sid, uid, function (err: Error) { should.exist(err); done(); }); })
// import { describe, it } from "mocha-typescript" describe('pinus', function () { describe('#createApp', function () { it('should create and get app, be the same instance', function (done: MochaDone) { let app = pinus.createApp({ base: mockBase }); should.exist(app); let app2 = pinus.app; should.exist(app2); should.strictEqual(app, app2); done(); }); }); });
it('should emit a error if master agent listen a port in use', function(done) { var master = new Master(); var invalidPort = 80; var errorCount = 0; master.on('error', function() { errorCount++; }); master.listen(invalidPort); setTimeout(function() { errorCount.should.equal(1); done(); }, WAIT_TIME); });
before(function(done) { //start remote server var opts = { acceptorFactory: Server.TcpAcceptor, paths: paths, port: port, bufferMsg: true, interval: 30 }; gateway = Server.create(opts); gateway.start(); done(); });
it('should register before filter by calling before method and fire filter chain by calling beforeFilter', function (done: MochaDone) { let session = new MockSession(); let service = new FilterService(); service.before(mockFilter1); service.before(mockFilter2); service.beforeFilter(null, {}, session, function () { should.exist(session); session.beforeCount1.should.equal(1); session.beforeCount2.should.equal(1); session.afterCount1.should.equal(0); session.afterCount2.should.equal(0); done(); }); });
after(function(done) { //stop remote server gateway.stop(); done(); });
it('should getStatisticsInfo', function (done: MochaDone) { let service = new ConnectionService(mockApp); let uid1 = 'uid1', uid2 = 'uid2'; let info1 = { msg: 'msg1' }, info2 = { msg: 'msg2' }; service.increaseConnectionCount(); service.increaseConnectionCount(); service.increaseConnectionCount(); service.addLoginedUser(uid1, info1); service.addLoginedUser(uid2, info2); let sinfo = service.getStatisticsInfo(); sinfo.should.have.property('serverId', 'connector-server-1'); sinfo.should.have.property('totalConnCount', 3); sinfo.should.have.property('loginedCount', 2); let infos = sinfo.loginedList; should.exist(infos); infos.length.should.equal(2); infos.should.containEql(info1); infos.should.containEql(info2); done(); });
before(function(done) { gateways = []; //start remote logger var item, opts; for(var i=0, l=serverList.length; i<l; i++) { item = serverList[i]; opts = { paths: records, port: item.port, context: {id: item.id} }; var gateway = Server.create(opts); gateways.push(gateway); gateway.start(); } done(); });
describe('#use', function () { it('should exist plugin component and event', function (done: MochaDone) { let plugin = { name: 'mock-plugin', components: [MockPlugin], events: [MockEvent] }; let opts = {}; app.use(plugin, opts); should.exist(app.event.listeners('bind_session')); should.exist(app.components.mockPlugin); done(); }); });
it('should fail if the monitor connect to the invalid address', function(done) { var monitor = new Monitor({}); var host = 'localhost'; var invalidPort = -80; var errorCount = 0; monitor.connect(invalidPort, host, function(err) { should.exist(err); errorCount++; }); setTimeout(function() { errorCount.should.equal(1); done(); }, WAIT_TIME); });
before(function(done) { //start remote server var opts = { acceptorFactory: Server.WSAcceptor, paths: paths, port: port, bufferMsg: true, interval: 30 }; gateway = Server.create(opts); gateway.start(); done(); });
it('should register after filter by calling after method and fire filter chain by calling afterFilter', function (done: MochaDone) { let session = new MockSession(); let service = new FilterService(); service.after(mockFilter1); service.after(mockFilter2); service.afterFilter(null, null, {}, session, null, function () { should.exist(session); session.beforeCount1.should.equal(0); session.beforeCount2.should.equal(0); session.afterCount1.should.equal(1); session.afterCount2.should.equal(1); done(); }); });
after(function(done) { //stop remote server gateway.stop(); done(); });