Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-blocking it() calls #1902

Closed
ORESoftware opened this issue Sep 24, 2015 · 6 comments
Closed

Non-blocking it() calls #1902

ORESoftware opened this issue Sep 24, 2015 · 6 comments

Comments

@ORESoftware
Copy link

I am sure you have had this question before but I am really struggling to find information about this online.

I am looking for a way to make it() calls non-blocking

currently, if I run this code:

var request = require('request');
var path = require('path');
var fs = require('fs');
var assert = require('assert');
var colors = require('colors');
var async = require('async');


describe('@Test_Enrichment*', function () {

    var config, constants, serverURL, serverPort;

    before(function () {
        config = require('univ-config')(this.test.parent.title, 'setup/testSetup');
        constants = config.get('sc_constants');
        serverURL = config.get('test_env').smartconnect_server_config.url;
        serverPort = config.get('test_env').smartconnect_server_config.port;
    });


   fs.readdirSync(__dirname + '/test_data/enriched_payloads').filter(function (file) {

        return (path.extname(file) === '.json');

    }).map(function (file) {

        return __dirname + '/test_data/enriched_payloads/' + file;

   }).forEach(function (file) {

        it('[test] ' + path.basename(file), function (done) {
            var jsonDataForEnrichment = require(file);
            jsonDataForEnrichment.customer.accountnum = "8497404620452729";
            jsonDataForEnrichment.customer.data.accountnum = "8497404620452729";

            var options = {
                url: serverURL + ':' + serverPort + '/event',
                json: true,
                body: jsonDataForEnrichment,
                method: 'POST'
            };

            request(options, function (error, response, body) {
                if (error) {
                    done(error);
                }
                else {
                    assert(response.statusCode == 201, "Error: Response Code");
                    done();
                }
            });
        });

       console.log(Date.now());   // this logging statement logs everything before any it() tests are invoked
    });
});

then I get this output:

CACSVML-13295:smartconnect amills001c$ mocha test/testEnrichment.js 
1443133002097
1443133002100
1443133002101
1443133002101
1443133002101
1443133002101
1443133002101
1443133002101
1443133002101
1443133002101
1443133002101
1443133002101
1443133002101
1443133002101
1443133002101
1443133002102
1443133002102
1443133002102
1443133002102
1443133002102
1443133002102
1443133002102
1443133002102
1443133002102
1443133002103
1443133002103
1443133002103
1443133002103
1443133002103
1443133002103


  @Test_Enrichment*
[2015-09-24 22:16:42.132Z] file=testSetup.js mod=SmartConnect 

runtime NODE_ENV: dev_local
    ✓ [test] Activate_CDV.json (248ms)
    ✓ [test] Active_HSI.json (226ms)
    ✓ [test] Appt.json (208ms)
    ✓ [test] Bill.json (212ms)
    ✓ [test] Billing.json (203ms)
    ✓ [test] Cable_Card.json (225ms)
    ✓ [test] Cable_Card_Issue.json (200ms)
    ✓ [test] Caption.json (212ms)
    ✓ [test] Channel_Lineup.json (205ms)
    ✓ [test] Guide_To_Be_Announced.json (202ms)
    ✓ [test] OMP.json (209ms)
    ✓ [test] On_Demand_General.json (204ms)
    ✓ [test] On_Demand_Issue_General.json (205ms)
    ✓ [test] Othr.json (209ms)
    ✓ [test] ParentalControl.json (203ms)
    ✓ [test] Phone_Block_Calls.json (226ms)
    ✓ [test] Phone_Long_Distance_Issue.json (203ms)
    ✓ [test] Phone_Number_Change.json (239ms)
    ✓ [test] Retention.json (198ms)
    ✓ [test] Retn.json (197ms)
    ✓ [test] Sale.json (208ms)
    ✓ [test] Sales.json (199ms)
    ✓ [test] Screen_Freeze.json (196ms)
    ✓ [test] Screen_Snow.json (208ms)
    ✓ [test] Store_Locator.json (205ms)
    ✓ [test] Tech.json (236ms)
    ✓ [test] Vacation_Hold.json (203ms)
    ✓ [test] Video_EAS.json (204ms)
    ✓ [test] Video_Unauthorized.json (200ms)
    ✓ [test] Xfinity_Home.json (200ms)


  30 passing (6s)

as you can see, and as you probably know, the it() callbacks are delayed such that one it() doesn't run before the previous one completes - in other words, they are synchronous or blocking.

Is there a way around this?

My tests take too long to run as is!

@danielstjules
Copy link
Contributor

Checkout https://github.com/danielstjules/mocha.parallel You could change that single describe to parallel. Note that it has limitations at the moment, including not being able to use nested suites.

Given that this "parallel" behavior is a bit tricky (and requires domains for clean exception handling), I can't see it being introduced into the core runner.

@boneskull
Copy link
Member

#849 #1373

@boneskull
Copy link
Member

never say never, but it would require a rewrite of Runner, Runnable, Suite... at minimum

@boneskull
Copy link
Member

domain support is another issue (#513) but definitely should be a prereq to anything like this

@danielstjules
Copy link
Contributor

Agreed. It would be nice if the browser could offer some sort of equivalent to domains. But even node is dropping them in favor of a solution that hasn't yet been completed. :( I think they're a poor solution for error handling in most projects, but there's some exceptions (like a test runner haha) where I think they'd be helpful.

@danielstjules
Copy link
Contributor

I think it'd be nice to keep browser and node logic (including error handling) as close as possible, and thus avoid domains, as we're not yet doing much in regards to browser tests. Though I guess the bigger issue is that we should start setting up automatic browser integration tests. It'd be a great way to avoid regressions too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants