TestApi.teardown and batch created entities


#1

Calling TestApi.teardown on a context tracking entities created with createBatchEntity is very slow.
I created hundreds of Measurements (all attached to the same timeseries).
Is there a way to improve the performances of TestApi.teardown and make it call a removeAll instead of remove?


#2

teardown already uses removeAll! I think what’s slowing down the teardown is the waiting for queues to drain especially if they have too many entries.


#3

Running teardown shows hundreds of remove with individual id.
Not sure what am I missing, why it is not using removeAll


#4

I think the only case where Type.remove is used is when someone explicitly uses the TestAPi.removeEntities function, in the other cases it’s either removeAll or removeBatch that’s used.

Can you check that you’re not calling removeEntities?


#5

Here is the code that is making the call to individual remove:

  var ctx = TestApi.createContext("FOO");

    function addMeasurementsTo(id) {
      var start = new DateTime("2016-01-01");
      var end = new DateTime("2016-02-01");
  
      var measurements = Measurement.array();
      for (var date = start; date < end; date = date.plusDays(1)) {
          measurements.push({
              start: date,
              end: date.plusDays(1),
              quantity: {
                  value: 0,
                  unit: {"id": "dimensionless"}
              },
              parent: {
                "id": id
              }
          });
      }

      TestApi.createBatchEntity(ctx, "Measurement", measurements);
    }

addMeasurementsTo("S41");
    
TestApi.teardown(ctx);

It seems that the behaviour is not the same when the header is also tracked by the TestApi ( here the header is not created by the TestApi )