All files / Nodejs/test throughMeteredTest.js

0% Statements 0/18
100% Branches 0/0
0% Functions 0/7
0% Lines 0/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                                               
var stream = require("../lib/streams.js");
 
describe("local", function() {
  it("Should able to meter through and emit when meter hits", function(done) {
    this.timeout(20 * 1000);
 
 
    var buffer = [];
    var throughMetered = stream.pipeline(stream.throughMetered({
        time: {
          seconds: 1
        }
      },
      (obj, done) => {
        //Should fail if we are in the middle of a emit because buffer would be null
        buffer.push(obj);
        done(null, {
          records: 1,
          size: 100,
          obj: obj
        });
      },
      (done) => {
        buffer = null;
        //add artificial delay so that the next write happens in this time
        setTimeout(() => {
          buffer = [];
          done();
        }, 400);
      }
    ), stream.devnull());
 
    throughMetered.write({
      i: 1
    });
    setTimeout(() => {
      throughMetered.write({
        i: 2
      });
      setTimeout(() => {
        throughMetered.write({
          i: 3
        });
        throughMetered.end(done);
      }, 1 * 1000 + 40);
    }, 1 * 1000 + 40);
  });
});