Get help with testing, discuss unit testing strategies etc.


Post by AaronTovo »

I have a problem where some of my tests take a long time to complete. Sometimes 15 seconds, sometimes 30 seconds. The assertions all pass instantly, but something in the background keeps running.

I suspect that the test harness is waiting for some asynchronous function to return but I can't identify the function. If I stop the debugger during the waiting time the call stack only shows that it's in garbage collection.

The following test consistently has a 15-second delay. The test harness configuration is shown below it.

What is causing these delays?
StartTest(function(t) {
    var aStore, srStore, form, mStore, drStore;
    var idBox,
        patientNameBox,
        patientBirthDateBox,
        accessionNumberBox,
        studyDescriptionBox,
        modalityBox,
        studyDateBox,
        clearResultsBox;

    t.diag("Search filter form test");

    t.chain(
        function (next) {
            srStore = Ext.create('StudySearch.store.SearchResults', { storeId: 'SearchResults' });
            aStore = Ext.create('StudySearch.store.Archives', { storeId: 'Archives' });
            mStore = Ext.create('StudySearch.store.Modalities', { storeId: 'Modalities' });
            drStore = Ext.create('StudySearch.store.DateRanges', { storeId: 'DateRanges' });

            // override with mock data urls
            aStore.model.proxy.url = './siesta-test/mock/archive.json';
            srStore.proxy.url = srStore.mintURL = '/my-home/siesta-test/mock/studies.json';
            t.loadStoresAndThen(aStore, srStore, next);
        },

        // load the store/model
        function(next) {
            t.ok(aStore.getCount() === 3, ' archives store has the right number of records');
            t.ok(srStore.getCount() === 50, 'Search Results store has the right number of records');

            // store/model is loaded.
            t.requireOk('StudySearch.view.SearchForm', next);
        },

        // test the view
        function(next) {
            form = Ext.create('StudySearch.view.SearchForm', { renderTo: Ext.getBody() });
            t.ok(form, 'SearchForm view created');

            form.keyNav = Ext.create('Ext.util.KeyNav', form.el, {
                enter: function() { form.submit(); }
            });

            t.pass("Form could be rendered");

            idBox = form.down('[name="patientId"]');
            patientNameBox = form.down('[name="patientName"]');
            patientBirthDateBox = form.down('[name="patientBirthDate"]');
            accessionNumberBox = form.down('[name="accessionNumber"]');
            studyDescriptionBox = form.down('[name="studyDescription"]');
            modalityBox = form.down('[name="modality"]');
            studyDateBox = form.down('[name="studyDate"]');
            clearResultsBox = form.down('[name="clearResults"]');

            t.click(patientNameBox,  next);
        },
        function(next) {
            patientNameBox.focus();
            t.type(patientNameBox.inputEl, 'Schmoe, Joe', next);
        },
        function (next) {
            t.is(patientNameBox.getValue(), "Schmoe, Joe", 'Correct text found in name field', next);
        },
        function(next) {
            t.done();
        }
    ); // end chain
})
var Harness = Siesta.Harness.Browser.ExtJS;

Harness.configure({
    title       : 'Awesome Test Suite',
    loaderPath  : { 'StudySearch' : '/test-home/study-search' },
    waitForAppReady: false,
    expectedGlobals: [
        'Ext',
        'VI',
        'TR'
    ],
    preload     : [
        "siesta-test/lib/ext4/resources/mythemes/css/mytheme.css",
        "siesta-test/lib/ext4/ext-all-debug.js",
        "siesta-test/lib/ext4/locale/ext-lang-en.js",
        "study-search/Utils.js",    

        // enable Ext.Loader.  
        {
            text: 'Ext.Loader.setConfig({ enabled : true, path : "study-search", disableCaching: false })'
        }
    ]
});

Harness.start(
    {
        hostPageUrl: 'testHostPage',  // this brings in the definition of TR
        url: 'siesta-test/040_search_form.t.js'
    }
);


Post by mats »

The step with t.is does not call next. After t.is(), add a next(); call.

Post Reply