<commit_before>var wq = require('../lib/wq.js')
  , testutil = require('testutil')
  , batch = require('batchflow')

var WQ_NAME = 'wqtest'
var q = null

describe('wq', function() {
  beforeEach(function(done) {
    wq.create({name: WQ_NAME}, function(err, _q) {
      if (err) return done(err)
      q = _q
      done()
    })
  })

  afterEach(function(done) {
    wq.destroy({name: WQ_NAME}, function(err) {
      if (err) return done(err)
      done()
    })
  })

  describe('queue counts', function() {
    describe('> when three objects are enqueued', function() {
      it('the waiting q should have a count of 3 and others have a count of 0', function(done) {
        var data = [{name: 'JP'}, {name: 'Leslie'}, {name: 'Chris'}]
        batch(data).seq().each(function(i, item, next) {
          q.enq(item, i, next)
        })
        .error(done)
        .end(function() {
          q.count(function(err, counts) {
            if (err) return done(err)
            EQ (counts.waiting, 3)
            EQ (counts.running, 0)
            EQ (counts.done, 0)
            done()
          })
        })
      })
    })
  })
})<commit_msg>update counts after deq<commit_after>var wq = require('../lib/wq.js')
  , testutil = require('testutil')
  , batch = require('batchflow')

var WQ_NAME = 'wqtest'
var q = null

describe('wq', function() {
  beforeEach(function(done) {
    wq.create({name: WQ_NAME}, function(err, _q) {
      if (err) return done(err)
      q = _q
      done()
    })
  })

  afterEach(function(done) {
    wq.destroy({name: WQ_NAME}, function(err) {
      if (err) return done(err)
      done()
    })
  })

  describe('queue counts', function() {
    describe('> when three objects are enqueued', function() {
      it('the waiting q should have a count of 3 and others have a count of 0', function(done) {
        var data = [{name: 'JP'}, {name: 'Leslie'}, {name: 'Chris'}]
        batch(data).seq().each(function(i, item, next) {
          q.enq(item, i, next)
        })
        .error(done)
        .end(function() {
          q.count(function(err, counts) {
            if (err) return done(err)
            EQ (counts.waiting, 3)
            EQ (counts.running, 0)
            EQ (counts.done, 0)
            done()
          })
        })
      })
    })

    describe('> when three objects are enqueued and one is dequeued', function() {
      it('the waiting q should have a count of 2 and running should have a count of 1 and done should have a count of 0', function(done) {
        var data = [{name: 'JP'}, {name: 'Leslie'}, {name: 'Chris'}]
        batch(data).seq().each(function(i, item, next) {
          q.enq(item, i, next)
        })
        .error(done)
        .end(function() {
          q.deq(function(err, item) {
            if (err) return done(err)
            EQ (item.data.name, 'JP')
            q.count(function(err, counts) {
              if (err) return done(err)
              EQ (counts.waiting, 2)
              EQ (counts.running, 1)
              EQ (counts.done, 0)
              done()
            })
          })
        })
      })
    })
  })
})
{'fraction_non_alphanumeric': 0.15747273893521488, 'fraction_numerical': 0.005131494547787043, 'mean_word_length': 1.959203036053131, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6294837', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1023, 'n_words': 271}