<commit_before><html>
    <head>
        <link rel="stylesheet" href="lib/qunit/qunit.css" media="all" />
        <script type="text/javascript" src="lib/qunit/qunit.js"></script>
        <script type="text/javascript" src="../src/comet.client.js"></script>
        <script type="text/javascript">
            var MESSAGE_BOUNCE_JSON = {content: 'Hello world!'};
            var client = comet('http://localhost:8080/nodecomet');
            var isWebSocketClient = client.type == 'websocket';
            var isLongPollingCLient = client.type == 'longpolling';
            
            function runSendTest(options) {
                asyncTest(options.testName, function() {
                    client.onmessage = function(message) {
                        options.onmessage(message);
                        start();
                    };
                    
                    client.onerror = function(error) {
                        options.onerror(error);
                        start();
                    }
                    
                    client.send(options.message);
                });
            }
        
            window.onload = function() {
                module("Basic stuff");
                
                test("Use of correct engine", function() {
                    if(window.WebSocket) {
                        ok(isWebSocketClient, "Client should be an instance of WebSocketClient");
                    } else {
                        ok(isLongPollingCLient, "Client should be an instance of LongPollingClient");
                    }
                });
                
                module("Communication");
                
                runSendTest({
                    testName: 'Message bounce',
                    message: MESSAGE_BOUNCE_JSON,
                    
                    onmessage: function(message) {
                        same(MESSAGE_BOUNCE_JSON, message, "Messages match");
                    },
                    onerror: function(error) {
                        ok(false, 'Received error: ' + error);
                    }
                });
                
                runSendTest({
                    testName: 'Bad message',
                    message: undefined,
                    
                    onmessage: function(receivedMessage) {
                        ok(false, 'An error should have been thrown');
                    },
                    onerror: function(error) {
                        ok(true, 'Received error: ' + error);
                    }
                });
            }
        </script>
    </head>
    <body>
        <h1 id="qunit-header">node-comet unit tests</h1>
        <h2 id="qunit-banner"></h2>
        <h2 id="qunit-userAgent"></h2>
        <ol id="qunit-tests"></ol>
    </body>
</html><commit_msg>Added message queueing test<commit_after><html>
    <head>
        <link rel="stylesheet" href="lib/qunit/qunit.css" media="all" />
        <script type="text/javascript" src="lib/qunit/qunit.js"></script>
        <script type="text/javascript" src="../src/comet.client.js"></script>
        <script type="text/javascript">
            var MESSAGE_BOUNCE_JSON = {content: 'Hello world!'};
            var client = comet('http://localhost:8080/nodecomet');
            var isWebSocketClient = client.type == 'websocket';
            var isLongPollingCLient = client.type == 'longpolling';
            
            function sendTest(options) {
                test(options.testName, function() {
                    var expectedCount = options.messages.length;
                    var receiveCount = 0;
                    
                    stop(options.timeout || 1000);
                    
                    client.onmessage = function(message) {
                        options.onmessage(message);
                        if(++receiveCount == expectedCount) start();
                    };
                    
                    client.onerror = function(error) {
                        options.onerror(error);
                        if(++receiveCount == expectedCount || options.startOnError) start();
                    }
                    
                    for(var i=0; i<expectedCount; i++) {
                        client.send(options.messages[i]);
                    }
                });
            }
        
            window.onload = function() {
                module("Basics");
                
                test("Use of correct engine", function() {
                    if(window.WebSocket) {
                        ok(isWebSocketClient, "Client should be an instance of WebSocketClient");
                    } else {
                        ok(isLongPollingCLient, "Client should be an instance of LongPollingClient");
                    }
                });
                
                module("Communication");
                
                sendTest({
                    testName: 'Message bounce',
                    messages: [MESSAGE_BOUNCE_JSON],
                    
                    onmessage: function(message) {
                        same(MESSAGE_BOUNCE_JSON, message, "Messages match");
                    },
                    onerror: function(error) {
                        ok(false, 'Received error: ' + error);
                    }
                });
                
                sendTest({
                    testName: 'Bad message',
                    messages: [undefined],
                    
                    onmessage: function(message) {
                        ok(false, 'An error should have been thrown');
                    },
                    onerror: function(error) {
                        ok(true, 'Received error: ' + error);
                    }
                });
                
                var queueingMessages = [];
                for(var i=0; i<100; i++) {
                    queueingMessages.push(MESSAGE_BOUNCE_JSON);
                }
                
                sendTest({
                    testName: 'Message queueing',
                    messages: queueingMessages,
                    timeout: 10000,
                    startOnError: true,
                    
                    onmessage: function(message) {
                        same(MESSAGE_BOUNCE_JSON, message, "Messages match");
                    },
                    onerror: function(error) {
                        ok(false, 'Received error: ' + error);
                    }
                });
            }
        </script>
    </head>
    <body>
        <h1 id="qunit-header">node-comet unit tests</h1>
        <h2 id="qunit-banner"></h2>
        <h2 id="qunit-userAgent"></h2>
        <ol id="qunit-tests"></ol>
    </body>
</html>
{'fraction_non_alphanumeric': 0.10571260306242639, 'fraction_numerical': 0.005153121319199058, 'mean_word_length': 1.0485524728588662, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 45, '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': '5955492', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1521, 'n_words': 297}