<commit_before>/**
 * XadillaX created at 2016-06-06 21:40:48 With ♥
 *
 * Copyright (c) 2016 Souche.<EMAIL>, all rights
 * reserved.
 */
"use strict";

require("should");

var config = require("./config");
var Consumer = require("../").Consumer;

describe("#consumer", function() {
    var consumer = new Consumer(config.consumerId, config.topic, "*", config.accessKey, config.secretKey);
    var date = new Date();
    var DATE = date.getUTCFullYear() + date.getUTCMonth() + date.getUTCDate();
    var _ack;

    this.timeout(0);

    it("should start consumer", function(done) {
        consumer.init(function() {
            consumer.listen();
            done();
        });
    });

    it("should get one message", function(done) {
        consumer.once("message", function(message, ack) {
            message.topic.should.be.eql(config.topic);
            message.tag.should.be.eql("tagA");
            message.key.should.be.eql("");
            message.msgId.should.match(/^[0-9A-Z]{32}$/);
            message.body.should.be.eql("Hello " + DATE);
            message.reconsumeTimes.should.be.eql(0);

            _ack = ack;
            done();
        });
    });

    it("should get another message", function(done) {
        consumer.once("message", function(message, ack) {
            _ack = ack;

            message.topic.should.be.eql(config.topic);
            message.tag.should.be.eql("tagA");
            message.key.should.be.eql("");
            message.msgId.should.match(/^[0-9A-Z]{32}$/);
            message.body.should.be.eql("World " + DATE);
            message.reconsumeTimes.should.be.eql(0);

            done();
        });

        _ack.done(false);
    });

    it("should reconsume", function(done) {
        consumer.once("message", function(message, ack) {
            message.topic.should.be.eql(config.topic);
            message.tag.should.be.eql("tagA");
            message.key.should.be.eql("");
            message.msgId.should.match(/^[0-9A-Z]{32}$/);
            message.body.should.be.eql("Hello " + DATE);
            message.reconsumeTimes.should.be.eql(1);

            ack.done();

            done();
        });

        _ack.done(true);
    });

    it("should stop producer", function(done) {<commit_msg>fix consumer test<commit_after>/**
 * XadillaX created at 2016-06-06 21:40:48 With ♥
 *
 * Copyright (c) 2016 Souche.<EMAIL>, all rights
 * reserved.
 */
"use strict";

require("should");

var config = require("./config");
var Consumer = require("../").Consumer;

describe("#consumer", function() {
    var consumer = new Consumer(config.consumerId, config.topic, "*", config.accessKey, config.secretKey);
    var date = new Date();
    var DATE = date.getUTCFullYear() + date.getUTCMonth() + date.getUTCDate();
    var _ack = null;
    var _message = null;

    this.timeout(0);

    function listener(message, ack) {
        _message = message;
        _ack = ack;
    }

    it("should start consumer", function(done) {
        consumer.on("message", listener);
        consumer.init(function() {
            consumer.listen();
            done();
        });
    });

    it("should get one message", function(done) {
        // consumer.once("message", function(message, ack) {
        //     

        //     _ack = ack;
        //     done();
        // });
        function verify() {
            if(_ack === null) return setTimeout(verify, 500);

            _message.topic.should.be.eql(config.topic);
            _message.tag.should.be.eql("tagA");
            _message.key.should.be.eql("");
            _message.msgId.should.match(/^[0-9A-Z]{32}$/);
            _message.body.should.be.eql("Hello " + DATE);
            _message.reconsumeTimes.should.be.eql(0);

            _message = null;
            _ack.ack(false);
            _ack = null;

            done();
        }

        setTimeout(verify, 500);
    });

    it("should get another message", function(done) {
        function verify() {
            if(_ack === null) return setTimeout(verify, 500);

            _message.topic.should.be.eql(config.topic);
            _message.tag.should.be.eql("tagA");
            _message.key.should.be.eql("");
            _message.msgId.should.match(/^[0-9A-Z]{32}$/);
            _message.body.should.be.eql("World " + DATE);
            _message.reconsumeTimes.should.be.eql(0);

            _message = null;
            _ack.ack(true);
            _ack = null;

            done();
        }

        setTimeout(verify, 500);
    });

    it("should reconsume", function(done) {
        function verify() {
            if(_ack === null) return setTimeout(verify, 500);

            _message.topic.should.be.eql(config.topic);
            _message.tag.should.be.eql("tagA");
            _message.key.should.be.eql("");
            _message.msgId.should.match(/^[0-9A-Z]{32}$/);
            _message.body.should.be.eql("Hello " + DATE);
            _message.reconsumeTimes.should.be.eql(1);

            _ack.done(true);

            done();
        }

        setTimeout(verify, 500);
    });

    it("should stop consumer", function(done) {
{'fraction_non_alphanumeric': 0.16695957820738136, 'fraction_numerical': 0.016793595000976373, 'mean_word_length': 1.9848484848484849, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1633965', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1576, 'n_words': 261}