Skip to content
Advertisement

CA Rally – Concurrency conflict: [Object has been modified since being read for update in this context] Error

I have an array of testcases that I am attempting to add to a testset in Rally using the rally api’s.

I iterate through the array and call this method for every testcase in the array. They are all being added to the same testset.

RallyConnect.prototype.addTestCaseToSet = function (tcObjectID, tcRef, tsObjectID, tsRef) {
    return new Promise((resolve, reject) => {

        // check to make sure it doesn't already exist
        rallyApi.query({
            ref: '/testset/' + tsObjectID + '/testcases',
            fetch: "true",
            query: queryUtils.where('ObjectID', '=', tcObjectID)
        }, function (error, result) {
            if (error) {
                reject(error);
            } else {
                if (result.TotalResultCount > 0) {
                   resolve({ tsRef: tsRef, tcRef: tcRef, action: 'exists' });
                } else {
                        rallyApi.add({
                            ref: tsRef,
                            collection: 'TestCases',
                            data: [{ _ref: refUtils.getRelative(tcRef) }]
                        }, function (error, result) {
                            if (error) {
                                reject(error);
                            } else {
                                resolve({ tsRef: tsRef, tcRef: tcRef, action: 
 'added' });
                            }
                        });
                }
            }
        });
        //});
    });
}

I get the following error quite a bit and the process fails

Error: Could not add artifact to collection
    at generateError (C:srctesting_utilitynode_modulesrallydistrequest.js:38:11)
    at Request._callback (C:srctesting_utilitynode_modulesrallydistrequest.js:118:22)
    at Request.self.callback (C:srctesting_utilitynode_modulesrallynode_modulesrequestrequest.js:187:22)
    at emitTwo (events.js:125:13)
    at Request.emit (events.js:213:7)
    at Request.<anonymous> (C:srctesting_utilitynode_modulesrallynode_modulesrequestrequest.js:1044:10)
    at emitOne (events.js:115:13)
    at Request.emit (events.js:210:7)
    at Gunzip.<anonymous> (C:srctesting_utilitynode_modulesrallynode_modulesrequestrequest.js:965:12)
    at emitNone (events.js:110:20)
  errors:
   [ 'Could not add artifact to collection',
     'Concurrency conflict: [Object has been modified since being read for update in this context] - ConcurrencyConflictException : Modified since read on update
: Object Class : com.f4tech.slm.domain.TestSet : ObjectID : 203533554680' ] }

Has anyone else run into this issues and know what I can do to ensure I don’t get it.

Advertisement

Answer

Rather than looping and adding the test cases one at a time, can you add them in a batch?

rallyApi.add({
    ref: tsRef,
    collection: 'TestCases',
    data: [
        { _ref: refUtils.getRelative(tcRef1) },
        { _ref: refUtils.getRelative(tcRef2) }, //include multiples here
        { _ref: refUtils.getRelative(tcRef3) },
        { _ref: refUtils.getRelative(tcRef4) },
    ]
});

Note, this approach is limited to 25 records per batch I think, so depending on how much data you’re generally associating to a test set you may have to break it up into chunks of 25.

The other thing to check, is are you using the same rallyApi instance for each of the calls? From your code it seems like it. As long as this is true, and as long as cookies are enabled I think you should be pinned to the same app server for all your requests and shouldn’t be seeing these exceptions (which are usually caused by quick updates to related objects during background cache syncing across all the server nodes).

You can also try adding this config when newing up your rallyApi instance:

{
    requestOptions: { jar: true }
}

That should ensure your requests are maintaining cookies.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement