<commit_before>'use strict';

var spawn = require('child_process').spawn;
var Buffer = require('buffer');
var request = require('supertest');
var async = require('async');
var helper = require('./helpers/testhelper.js');

var host = 'http://localhost:3000';
request = request(host);

describe('Check the API of cluster', function(){
	var clusterExe;
	//run cluster
	before(function(done){
		clusterExe = spawn('node', ['./test/helpers/cluster_help.js']);
		clusterExe.stdout.on('data', function(data){
			console.log("data:", data.toString('utf8'));
			
			if(data.toString('utf8')==="Launch api is ok\n"){
				console.log("Launch test");
				done();
			}
		});
	});
	//kill cluster
	after(function(done){
		console.log("kill cluster");
		clusterExe.kill('SIGINT');
		done();
	});


	it('Check express is open', function(done){
		request
			.get('/status')
			.expect(200)
			.expect('Content-Type', /application\/json/)
			.end(function(err,res){
				if(err){
					console.log("Not found");
					done(err);					
				}
				else{				
					done();
				}
			});
	});

	it('Check status function', function(done){
		request
			.get('/status')
			.expect(200)
			.expect('Content-Type', /application\/json/)
			.end(function(err,res){
				if(err){
					done(err);
				}
				else{
					var result = JSON.parse(res.text);
					expect(result).to.have.property('cluster');
					expect(result).to.have.deep.property('cluster.pid');
					expect(result).to.have.deep.property('cluster.cpu');
					expect(result).to.have.deep.property('cluster.memory');
					expect(result.workers).to.be.a('array');
					expect(result.workers[0]).to.have.property('id');
					expect(result.workers[0]).to.have.property('pid');
					expect(result.workers[0]).to.have.property('cpu');
					expect(result.workers[0]).to.have.property('memory');
					done();
				}
			});						
	});
	it('Check status for one worker', function(done){
		async.waterfall([			
			helper.getStatus,
			function(statusAll, cb){
				var worker = statusAll.workers[0];
				request
					.get('/status/' + worker.id)
					.expect(200)
					.expect('Content-Type', /application\/json/)
					.end(function(err,res){
						if(err){
							cb(err);
						}
						else{
							var result = JSON.parse(res.text);
							expect(result.worker).to.have.property('id');
							expect(result.worker).to.have.property('pid');
							expect(result.worker).to.have.property('cpu');
							expect(result.worker).to.have.property('memory');
							cb();
						}						
					});			
			}
		], done);
	});
	it('Restart all workers', function(done){
		async.series([
			function(callback){
				request
					.get('/restart')
					.expect(200)
					.expect('Content-Type', /application\/json/)
					.end(function(err,res){
						if(err){
							callback(err);
						}
						else{
							var result = JSON.parse(res.text);					
							expect(result).to.have.deep.property('restart.restarted');
							expect(result.restart.restarted).to.be.a('number');										
							callback();
						}
					});	
			},
			function(callback){
				helper.getStatus(function(error, body){
					callback();
				});
			}
		], done)
	
	});	
	it('Restart one worker', function(done){
		var idWorker = 0;
		async.waterfall([			
			helper.getStatus,
			function(statusAll, cb){
				var worker = statusAll.workers[0];
				idWorker = worker.id;
				request
					.get('/restart/' + worker.id)
					.expect(200)
					.expect('Content-Type', /application\/json/)
					.end(function(err,res){
						if(err){
							cb(err);
						}
						else{
							var result = JSON.parse(res.text);					
							expect(result).to.have.deep.property('restart.restarted');
							expect(result.restart.restarted).to.be.a('number');										
							cb();
						}						
					});			
			},
			function(cb){
				helper.getStatusWorker(idWorker, function(err, body){
					cb();
				});
			}

		],done);
	});
	it('Shutdown all workers');
	it('Shutdown one worker');
	it('Add one worker');
	it('Add a especific number of workers');
	it('Get the log of cluster');
});<commit_msg>Refactor test<commit_after>'use strict';

var spawn = require('child_process').spawn;
var Buffer = require('buffer');
var request = require('supertest');
var async = require('async');
var helper = require('./helpers/testhelper.js');

var host = 'http://localhost:3000';
request = request(host);

describe('Check the API of cluster', function(){
	var clusterExe;
	//run cluster
	before(function(done){
		clusterExe = spawn('node', ['./test/helpers/cluster_help.js']);
		clusterExe.stdout.on('data', function(data){
			console.log("data:", data.toString('utf8'));
			
			if(data.toString('utf8')==="Launch api is ok\n"){
				console.log("Launch test");
				done();
			}
		});
	});
	//kill cluster
	after(function(done){
		console.log("kill cluster");
		clusterExe.kill('SIGINT');
		done();
	});


	it('Check express is open', function(done){
		request
			.get('/status')
			.expect(200)
			.expect('Content-Type', /application\/json/)
			.end(function(err,res){
				if(err){
					console.log("Not found");
					done(err);					
				}
				else{				
					done();
				}
			});
	});

	it('Check status function', function(done){
		request
			.get('/status')
			.expect(200)
			.expect('Content-Type', /application\/json/)
			.end(function(err,res){
				if(err){
					done(err);
				}
				else{
					var result = JSON.parse(res.text);
					expect(result).to.have.property('cluster');
					expect(result).to.have.deep.property('cluster.pid');
					expect(result).to.have.deep.property('cluster.cpu');
					expect(result).to.have.deep.property('cluster.memory');
					expect(result.workers).to.be.a('array');
					expect(result.workers[0]).to.have.property('id');
					expect(result.workers[0]).to.have.property('pid');
					expect(result.workers[0]).to.have.property('cpu');
					expect(result.workers[0]).to.have.property('memory');
					done();
				}
			});						
	});
	it('Check status for one worker', function(done){
		async.waterfall([			
			helper.getStatus,
			function(statusAll, cb){
				var worker = statusAll.workers[0];
				request
					.get('/status/' + worker.id)
					.expect(200)
					.expect('Content-Type', /application\/json/)
					.end(function(err,res){
						if(err){
							cb(err);
						}
						else{
							var result = JSON.parse(res.text);
							expect(result.worker).to.have.property('id');
							expect(result.worker).to.have.property('pid');
							expect(result.worker).to.have.property('cpu');
							expect(result.worker).to.have.property('memory');
							cb();
						}						
					});			
			}
		], done);
	});
	it('Restart all workers', function(done){
		async.series([
			function(callback){
				request
					.get('/restart')
					.expect(200)
					.expect('Content-Type', /application\/json/)
					.end(function(err,res){
						if(err){
							callback(err);
						}
						else{
							var result = JSON.parse(res.text);					
							expect(result).to.have.deep.property('restart.restarted');
							expect(result.restart.restarted).to.be.a('number');										
							callback();
						}
					});	
			},
			function(callback){
				helper.getStatus(function(error, body){
					callback();
				});
			}
		], done)
	
	});	
	it('Restart one worker', function(done){
		var idWorker = 0;
		async.waterfall([			
			helper.getStatus,
			function(statusAll, cb){
				var worker = statusAll.workers[0];
				idWorker = worker.id;
				request
					.get('/restart/' + worker.id)
					.expect(200)
					.expect('Content-Type', /application\/json/)
					.end(function(err,res){
						if(err){
							cb(err);
						}
						else{
							var result = JSON.parse(res.text);					
							expect(result).to.have.deep.property('restart.restarted');
							expect(result.restart.restarted).to.be.a('number');										
							cb();
						}						
					});			
			},
			function(cb){
				helper.getStatusWorker(idWorker, function(err, body){
					cb();
				});
			}

		],done);
	});
	it('Shutdown all workers', function(err, body){
		async.waterfall([
		    helper.getStatus,
		    function(statusAll, cb){
		    	request
		    		.get('/shutdown')
		    		.expect(200)
		    		.expect('Content-Type', /application\/json/)
		    		.end(function(err, res){
		    			if(err){
		    				cb(err);
		    			}
		    			else{
							var result = JSON.parse(res.text);					
							expect(result).to.have.deep.property('shutdwon.shutdown');
							expect(result.restart.restarted).to.be.a('number');										
							cb(null,statusAll);
		    			}
		    		});
		    },
		    function(beginStatus, cb){
		    	helper.getStatus(function(err, status){
		    		cb(err, beginStatus, status);
		    	});
		    },
		    function(beginStatus, actualStatus, cb){
		    	expect(beginStatus.workers.length).
		    }
		], done)
	});
	it('Shutdown one worker');
	it('Add one worker');
	it('Add a especific number of workers');
	it('Get the log of cluster');
});
{'fraction_non_alphanumeric': 0.1864521210757286, 'fraction_numerical': 0.006638910768538314, 'mean_word_length': 2.6396396396396398, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2535383', 'n_tokens_mistral': 3976, 'n_tokens_neox': 2902, 'n_words': 461}