Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let server;
  2.  
  3. describe('Node.js Unified Logging', function() {
  4.   describe('Middleware With Async Hooks', function() {
  5.     before(function(done) {
  6.       // start server
  7.       server = app.listen(3000, () => {
  8.         console.log('listening on port 3000');
  9.       });
  10.       // make a request
  11.       request('http://localhost:3000/home', function (error, response, body) {
  12.         done();
  13.       });
  14.     });
  15.     after(function() {
  16.       // close server when done
  17.       server.close();
  18.     });
  19.     it('makes logs', function() {
  20.       return logArray.should.not.be.empty;
  21.     });
  22.     let objs = [];
  23.     it('makes logs that contain JSON', function() {
  24.       logArray.forEach((entry) => {
  25.         let bracketIdx = entry.indexOf('{');
  26.         let jsonStr = entry.substr(bracketIdx);
  27.         let obj = JSON.parse(jsonStr);
  28.         objs.push(obj);
  29.       });
  30.       return objs.should.not.be.empty;
  31.     });
  32.     it('makes logs that all have a span id', function() {
  33.       return objs.should.all.have.property('ul-span-id');
  34.     });
  35.     it('makes logs with matching head spans', function() {
  36.       const headSpanId = objs[0]['ul-ctx-head-span-id'];
  37.       return objs.should.all.have.property('ul-ctx-head-span-id', headSpanId);
  38.     });
  39.     it('makes logs with matching caller spans', function() {
  40.       const callerSpanId = objs[0]['ul-ctx-caller-span-id'];
  41.       return objs.should.all.have.property('ul-ctx-caller-span-id', callerSpanId);
  42.     });
  43.     it('makes logs that all have an operation name', function() {
  44.       return objs.should.all.have.property('ul-operation');
  45.     });
  46.     let homeLog;
  47.     let asyncLog;
  48.     let dbLog;
  49.     it('makes one log for the home operation', function() {
  50.       objs.forEach((log) => {
  51.         if (log['ul-operation'] === 'GET /home') {
  52.           homeLog = log;
  53.         } else if (log['ul-operation'] === 'GET /async') {
  54.           asyncLog = log;
  55.         } else if (log['ul-operation'] === 'GET /db') {
  56.           dbLog = log;
  57.         }
  58.       });
  59.       return homeLog.should.exist;
  60.     });
  61.     it('makes one log for the async operation', function() {
  62.       return asyncLog.should.exist;
  63.     });
  64.     it('makes one log for the db operation', function() {
  65.       return dbLog.should.exist;
  66.     });
  67.     it('logs the async span as a child of the home span', function() {
  68.       return homeLog['ul-span-id'].should.equal(asyncLog['ul-child-of']);
  69.     });
  70.     it('logs the db span as a child of the async span', function() {
  71.       return asyncLog['ul-span-id'].should.equal(dbLog['ul-child-of']);
  72.     });
  73.   });
  74. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement