<commit_before>/**
 * 
 */

var assert=require('assert');
assert.equal(true, true);

var ws=require('ws');

var testNumber=0;

function EchoTest(BridgeProxy, AutoConnectProxy, config, callback){

	var test=testNumber;
	testNumber++;
	
	//a ws server that just echos back all messages...
	var echo=(new ws.Server({
		port: config.echo
	})).on('connection', function(wsclient){

		wsclient.on('message',function(message){
			wsclient.send(message);
			console.log('endpoint echos: '+message);
		})

	});

	var basicauth='';
	basicauth='<PASSWORD>';


//	a bridge server. pairs clients with autoconnect proxy connections.
	var WSBridge=require('../bridgeproxy.js');
	var bridge=new WSBridge({
		port:config.bridge,
		basicauth:basicauth
	});
	var WSAuto=require('../autoconnectproxy.js');

	if(basicauth.length){
		basicauth=basicauth+'@';
	}
	var autoconnect=new WSAuto({source:'ws://'+basicauth+'localhost:'+config.bridge, destination:'ws://localhost:'+config.echo});

	var clients=0;

	var num=config.count;
	for(var i=0;i< num; i++){

		clients++;
		(function(i){
			var client=(new ws('ws://localhost:'+config.bridge)).on('open', function(){
				setTimeout(function(){
					var tm=setTimeout(function(){
						assert.fail('test '+test+' client#'+i+' expected response by now.');
						callback(true);
					}, 10000);
					client.on('message',function(message){

						assert.equal(message, 'hello world', 'test '+test+' client#'+i+' echo failure, recieved: '+message);
						console.log('test '+test+' client#'+i+' success');
						clearTimeout(tm);
						this.close();
						clients--;
						if(clients==0){

							setTimeout(function(){
								echo.close();
								autoconnect.close();
								bridge.close();
								callback(null);
							},100);

						}
					});
					//console.log('test client #'+i+' sends: hello world');

					client.send('hello world');
					
				}, i*100);

			});
		})(i);

	}

}

var series=require("async").series(
		[
        function(callback){
        	//test direct load
        	EchoTest(require('../bridgeproxy.js'), require('../autoconnectproxy.js'), {echo:9001, bridge:9002, count:50},callback);
        },
        function(callback){
        	// test same ports - cleanup must complete
        	EchoTest(require('../bridgeproxy.js'), require('../autoconnectproxy.js'), {echo:9001, bridge:9002, count:5},callback);
        },
        function(callback){
        	//test using index, this should be the same as require('node-rproxy')
        	EchoTest(require('../index.js').AutoConnect, require('../index.js').Bridge, {echo:9003, bridge:9004, count:5}, callback);
        }
        ],
        function(err, results) {
		    console.log(err);
		    console.log(results);
		});


<commit_msg>fail if async.series returns an error<commit_after>/**
 * 
 */

var assert=require('assert');
assert.equal(true, true);

var ws=require('ws');

var testNumber=0;

function EchoTest(BridgeProxy, AutoConnectProxy, config, callback){

	var test=testNumber;
	testNumber++;
	
	//a ws server that just echos back all messages...
	var echo=(new ws.Server({
		port: config.echo
	})).on('connection', function(wsclient){

		wsclient.on('message',function(message){
			wsclient.send(message);
			console.log('endpoint echos: '+message);
		})

	});

	var basicauth='';
	basicauth='<PASSWORD>:<PASSWORD>';


//	a bridge server. pairs clients with autoconnect proxy connections.
	var WSBridge=require('../bridgeproxy.js');
	var bridge=new WSBridge({
		port:config.bridge,
		basicauth:basicauth
	});
	var WSAuto=require('../autoconnectproxy.js');

	if(basicauth.length){
		basicauth=basicauth+'@';
	}
	var autoconnect=new WSAuto({source:'ws://'+basicauth+'localhost:'+config.bridge, destination:'ws://localhost:'+config.echo});

	var clients=0;

	var num=config.count;
	for(var i=0;i< num; i++){

		clients++;
		(function(i){
			var client=(new ws('ws://localhost:'+config.bridge)).on('open', function(){
				setTimeout(function(){
					var tm=setTimeout(function(){
						assert.fail('test '+test+' client#'+i+' expected response by now.');
						callback(true, false);
					}, 10000);
					client.on('message',function(message){

						assert.equal(message, 'hello world', 'test '+test+' client#'+i+' echo failure, recieved: '+message);
						console.log('test '+test+' client#'+i+' success');
						clearTimeout(tm);
						this.close();
						clients--;
						if(clients==0){

							setTimeout(function(){
								echo.close();
								autoconnect.close();
								bridge.close();
								callback(null, true);
							},100);

						}
					});
					//console.log('test client #'+i+' sends: hello world');

					client.send('hello world');
					
				}, i*100);

			});
		})(i);

	}

}

var series=require("async").series(
		[
        function(callback){
        	//test direct load
        	EchoTest(require('../bridgeproxy.js'), require('../autoconnectproxy.js'), {echo:9001, bridge:9002, count:50},callback);
        },
        function(callback){
        	// test same ports - cleanup must complete
        	EchoTest(require('../bridgeproxy.js'), require('../autoconnectproxy.js'), {echo:9001, bridge:9002, count:5},callback);
        },
        function(callback){
        	//test using index, this should be the same as require('node-rproxy')
        	EchoTest(require('../index.js').AutoConnect, require('../index.js').Bridge, {echo:9003, bridge:9004, count:5}, callback);
        }
        ],
        function(err, results) {
		    if(err){
		    	assert.fail('tests failed');
		    }
		    console.log(results);
		});



{'fraction_non_alphanumeric': 0.18519185732300486, 'fraction_numerical': 0.015492704017294181, 'mean_word_length': 3.2544061302681992, 'pattern_counts': {'":': 0, '<': 8, '<?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': '710314', 'n_tokens_mistral': 2141, 'n_tokens_neox': 1763, 'n_words': 349}