<commit_before>$(document).ready(function(){
	
	var server = "/kanaloa/testsvc/";
	
	module("Basics");
	
	asyncTest("basic connect and onConnectionOpened disconnect", 4, function() {
		var connection = new KanaloaConnection(server);
		
		connection.onConnectionOpened = function() {
		    ok( true, "onConnectionOpened callback received" );
		    ok( (connection.connectionId), "connectionId has been set" );
		    
		    connection.disconnect();
		};
		
		connection.onConnectionClosed = function() {
		    ok( true, "onConnectionClosed callback received" );
		    equals( connection.connectionId, null, "connectionId has been unset" );
		    
		    start();
		};
		
		connection.connect();
	    });
	
	asyncTest("basic message send and receive with onDataReceived disconnect", 1, function() {
		var message = "test message " + (new Date()).getTime();
		
		var connection = new KanaloaConnection(server);

		connection.onDataReceived = function(data) {
		    equals(message, data.message, "received valid message");

		    connection.disconnect();
		    start();
		};
		
		connection.send(message);
	    });

	asyncTest("chained message send and receive (onMessageReceived send)", 1, function() {
		function newMessage() {
		    return "test message " + (new Date()).getTime();
		}
		
		var connection = new KanaloaConnection(server);
		var counter = 0;
		
		connection.onDataReceived = function(data) {
		    counter++;
		    
		    if (counter == 1) {
			connection.send(newMessage());
		    }
		    else {
			connection.disconnect();
			equals(2, counter, "received both messages");
			start();
		    }
		};
		
		connection.send(newMessage());
	    });<commit_msg>Slightly nicer test case. Good to check that the messages received are in fact the ones that we expect.<commit_after>$(document).ready(function(){
	
	var server = "/kanaloa/testsvc/";
	
	module("Basics");
	
	asyncTest("basic connect and onConnectionOpened disconnect", 4, function() {
		var connection = new KanaloaConnection(server);
		
		connection.onConnectionOpened = function() {
		    ok( true, "onConnectionOpened callback received" );
		    ok( (connection.connectionId), "connectionId has been set" );
		    
		    connection.disconnect();
		};
		
		connection.onConnectionClosed = function() {
		    ok( true, "onConnectionClosed callback received" );
		    equals( connection.connectionId, null, "connectionId has been unset" );
		    
		    start();
		};
		
		connection.connect();
	    });
	
	asyncTest("basic message send and receive with onDataReceived disconnect", 1, function() {
		var message = "test message " + (new Date()).getTime();
		
		var connection = new KanaloaConnection(server);

		connection.onDataReceived = function(data) {
		    equals(message, data.message, "received valid message");

		    connection.disconnect();
		    start();
		};
		
		connection.send(message);
	    });

	asyncTest("chained message send and receive (onMessageReceived send)", 3, function() {
		var connection = new KanaloaConnection(server);
		var counter = 0;
		
		connection.onDataReceived = function(data) {
		    counter++;
		    
		    if (counter == 1) {
			equals("first", data.message, "received first message");
			connection.send("second");
		    }
		    else {
			connection.disconnect();
			equals("second", data.message, "received second message");
			equals(2, counter, "received both messages");
			start();
		    }
		};
		
		connection.send("first");
	    });
{'fraction_non_alphanumeric': 0.13126629962329758, 'fraction_numerical': 0.0034772529701535787, 'mean_word_length': 3.3807106598984773, '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': '2215294', 'n_tokens_mistral': 1137, 'n_tokens_neox': 915, 'n_words': 251}