var pf = require('performanceFramework');
var qm = require('./queueMonitor.js');
var client = require('./client.js');
var server = require('./server.js');
var childProcess = require('child_process');
var numRequest = 1000;


var scenario4 = pf.describe('Rush benchmark - Flushing Queue', 'This test make ' + numRequest + ' requests to the ' +
    'listener without running the consumer. After that, the consumer is running to process requests and time is ' +
    'measured', 'wijmo', ['Time', 'Queued requests'], [], './log'); //monitor on localhost


var newTest = function(size, callback) {

    scenario4.test('test with ' + size + ' KB of response server', function (log, point) {
        'use strict';

        var count = 0;
        var server1 = server.createServer(0, size * 1024, function () {
            for (var i = 0; i < numRequest; i++) {
                client.client('localhost', 3001, "http://localhost:5001", function () {

                    count++;

                    if (count === numRequest) {

                        var time = new Date().valueOf();
                        point(0, numRequest);

                        var child = childProcess.fork('../src/consumer.js');

                        var monitorInterval = setInterval(function () {

                            qm.monitorQueue('wrL:hpri', function (value) {
                                var timePoint = (new Date().valueOf() - time) / 1000;
                                point(timePoint, value);

                                if (value === 0) {
                                    log(numRequest + ' requests of ' + size +  ' KB have been processed in ' + timePoint + ' s');
                                    process.kill(child.pid);
                                    //scenario4.done();
                                    server.closeServer(server1);
                                    clearInterval(monitorInterval);
                                    callback();
                                }
                            });
                        }, 1000);
                    }
                });
            }
        });
    });
}

var nTimes = 0;

function executeTest() {

    if (nTimes >= 5) {
        scenario4.done();
    } else {
        newTest((nTimes + 1) * 100, executeTest);
    }

    nTimes++;
}

executeTest();



@@ -216,17 +216,37 @@
 = 1000;%0A
+var numConsumer = 2;
 %0A
-
 %0Avar sce
@@ -587,16 +587,17 @@
 function
+ 
 (size, c
@@ -1175,16 +1175,123 @@
  child =
+ %5B%5D;%0A                        for (var i = 0; i %3C numConsumer; i++) %7B%0A                            child%5Bi%5D =
  childPr
@@ -1323,16 +1323,42 @@
 er.js');
+%0A                        %7D
 %0A%0A      
@@ -1771,17 +1771,16 @@
 + size +
- 
  ' KB ha
@@ -1819,24 +1819,104 @@
 nt + ' s');%0A
+                                    for (var i = 0; i %3C numConsumer; i++) %7B%0A    
             
@@ -1961,15 +1961,56 @@
 hild
+%5Bi%5D
 .pid);%0A
+                                    %7D%0A
     

add multiple consumer