[SERVER-20086] Avoid closing over $config.data in setup, teardown, and FSM state functions Created: 21/Aug/15  Updated: 19/Sep/15  Resolved: 02/Sep/15

Status: Closed
Project: Core Server
Component/s: Testing Infrastructure
Affects Version/s: 3.1.7
Fix Version/s: 3.1.8

Type: Bug Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Max Hirschhorn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QuInt 8 08/28/15, Quint 9 09/18/15
Participants:
Linked BF Score: 0

 Description   

The $config closed over by a function will actually refer to a copy of the workload configuration. This means that changes to the $config.data made by a workload B that extends a workload A will not be reflected if workload A uses $config.data explicitly in its functions. The modified $config.data is bound as the this value when the functions are executed and should be used instead.

The following JavaScript show the basic logic that the concurrency framework uses to let one workload configuration derive from another:

// Taken from parse_config.js, but removed the validation code.
function parseConfig(config) {
    config = Object.extend({}, config, true); // defensive deep copy
 
    config.startState = config.startState || 'init';
    config.setup = config.setup || Function.prototype;
    config.teardown = config.teardown || Function.prototype;
    config.data = config.data || {};
 
    return config;
}
 
// Taken from extend_workload.js, but removed the validation code.
function extendWorkload($config, callback) {
    var parsedSuperConfig = parseConfig($config);
    var childConfig = Object.extend({}, parsedSuperConfig, true);
    return callback(childConfig, parsedSuperConfig);
}
 
var $config = {}; // Normally would be defined by doing some load() call.
 
(function() {
    var extend1 = extendWorkload($config, function($config, $super) {
        $config.data.test = 'original';
 
        $config.setup = function setup(db, collName, cluster) {
            $super.setup.apply(this, arguments);
            print('using $config.data: ' + $config.data.test);
 
        };
 
        return $config;
    });
 
    var extend2 = extendWorkload(extend1, function($config, $super) {
        $config.data.test = 'changed';
 
        return $config;
    });
 
    extend2.setup.call(extend2.data); // See setupWorkload() in runner.js
})();
 
(function() {
    var extend1 = extendWorkload($config, function($config, $super) {
        $config.data.test = 'original';
 
        $config.setup = function setup(db, collName, cluster) {
            $super.setup.apply(this, arguments);
            print('using this: ' + this.test);
 
        };
 
        return $config;
    });
 
    var extend2 = extendWorkload(extend1, function($config, $super) {
        $config.data.test = 'changed';
 
        return $config;
    });
 
    extend2.setup.call(extend2.data); // See setupWorkload() in runner.js
})();

using $config.data: original
using this: changed



 Comments   
Comment by Githook User [ 02/Sep/15 ]

Author:

{u'username': u'visemet', u'name': u'Max Hirschhorn', u'email': u'max.hirschhorn@mongodb.com'}

Message: SERVER-20086 Avoid closing over $config.data in FSM tests.
Branch: master
https://github.com/mongodb/mongo/commit/991e9908f571c25e78f2e8eaf7c26e20471c50e2

Generated at Thu Feb 08 03:53:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.