1

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:\src\testing_utility\node_modules\rally\dist\request.js:38:11)
    at Request._callback (C:\src\testing_utility\node_modules\rally\dist\request.js:118:22)
    at Request.self.callback (C:\src\testing_utility\node_modules\rally\node_modules\request\request.js:187:22)
    at emitTwo (events.js:125:13)
    at Request.emit (events.js:213:7)
    at Request.<anonymous> (C:\src\testing_utility\node_modules\rally\node_modules\request\request.js:1044:10)
    at emitOne (events.js:115:13)
    at Request.emit (events.js:210:7)
    at Gunzip.<anonymous> (C:\src\testing_utility\node_modules\rally\node_modules\request\request.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.

3 Answers3

2

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.

Kyle Morse
  • 8,390
  • 2
  • 15
  • 16
  • Is there any Java alternative @Kyle? – Saikat Jul 10 '18 at 17:20
  • 1
    @psysane, the java toolkit should support cookies by default. It also exposes an updateCollection method to be able to bulk add/remove items from a collection. I'd suggest posting a new question if you continue to run into issues. – Kyle Morse Jul 10 '18 at 19:36
1

For the benefit of the community... I also got this error message, but for a somewhat different reason. I'll put it here, because it's the only place it's been discussed on the wider web. (If there's a discussion of it hidden away somewhere in in Rally's own forums, feel free to link!)

I got the error when attempting to save a Portfolio Feature item on which I had been making edits for a long time without saving (because it was a large field, and I don't like scrolling through endless miles of revision history).

I had four image.pngs on the item -- from things I'd pasted directly inline instead of including as attachments via an 'Image' button inset, and one or more of which the editor had vanished (as it sometimes does).

It was one or more of the missing image.png 'attachments' that it couldn't place, preventing it from saving. I deleted the image.png files from the attachments (without the actual images disappearing from the body of the field!) and it saved fine after that.

Nev
  • 11
  • 1
0

https://rally1.rallydev.com/slm/doc/webservice/

specifically: https://rally1.rallydev.com/slm/doc/webservice/bulk.jsp

unfortunately, I've not figured out how to add items to collections via bulk upload. I'm specifically adding defect references to a defect suite.

I am not using any lib....rather, I'm just calling the rally API (which is downright awful and reminds me of the 90s)

Jason
  • 2,451
  • 2
  • 23
  • 31
  • in Java / Spring, I ended up using https://stackoverflow.com/a/55165057/526664 as a guide...worked great. This solution causes all RestTemplate calls to go to the same Rally server (remember, this is all 90s tech and uses sticky sessions via cookies). This allows you to do a GET immediately after a CREATE – Jason Nov 25 '20 at 20:03