#1 2012-10-16 10:18:06

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Batchsending an empty batch results in error 400

We've created a unittest setting up a RestServer and a RestClient, when we start a batch on the client, and immediately after issue BatchSend the return value is 400 ...

procedure TLCSServerSessionTestBase.TestEmptyBatchSend;
var
  Ida: TIntegerDynArray;
begin
  Check(SQLWorkbaseRestClient.BatchStart(TSQLWorkbaseObject),'BatchStart failed');
  CheckEquals(HTML_SUCCESS,SQLWorkbaseRestClient.BatchSend(Ida),'Empty BatchSend failed'); // FAILS, RETURN VALUE = 400
end;

This same thing happens when we use Http, NamedPipe, or Messages

Is this designed behavior? We would think that sending an empty batch is not an error, even though it is not very efficient ;-)

[Edit]

I added a new Test to TTestExternalDatabase.CryptedDatabase, and this one fails too!

        Client2 := TSQLRestClientDB.Create(Model,nil,'testpass.db3',TSQLRestServerDB,false,password);
        try
          Client2.Server.DB.Synchronous := smOff;
          Client2.Server.DB.WALMode := true;
          Client2.Server.CreateMissingTables;
          Check(Client2.TransactionBegin(TSQLRecordPeople));
          Check(Client2.BatchStart(TSQLRecordPeople));
          while False do begin
            Check(R.ID<>0);
            Check(Client2.BatchAdd(R,true)>=0);
          end;
          Check(Client2.BatchSend(Res)=200);
          Client2.Commit;
        finally
          Client2.Free;
        end;

Last edited by Bascy (2012-10-16 11:41:39)

Offline

#2 2012-10-16 11:52:54

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Re: Batchsending an empty batch results in error 400

TSQLRestClientURI.BatchSend() really cannot cope with empty Batches, so I guess an enhancement is needed here:

Line 17810:

  ...
  try
    if fBatchCount = 0 then begin // Nothing to send
      result := HTML_SUCCESS;
      exit;
    end;

    fBatch.CancelLastComma;
...

Offline

#3 2012-10-16 12:19:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Batchsending an empty batch results in error 400

Thanks for the report.

Fixed by http://synopse.info/fossil/info/41a6ada266

Offline

#4 2012-10-18 06:57:09

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Re: Batchsending an empty batch results in error 400

Thanks for the fix!

Why not add a unittest for this particular problem so the test will ensure it will keep working in the future:

Synselftest.pas, line 4400

        Client2 := TSQLRestClientDB.Create(Model,nil,'testpass.db3',TSQLRestServerDB,false,password);
        try
          Client2.Server.DB.Synchronous := smOff;
          Client2.Server.DB.WALMode := true;
          Client2.Server.CreateMissingTables;
          Check(Client2.TransactionBegin(TSQLRecordPeople));
          Check(Client2.BatchStart(TSQLRecordPeople));
          Check(Client2.BatchSend(Res)=200);
          Client2.Commit;
        finally
          Client2.Free;
        end;

Offline

#5 2012-10-18 07:58:47

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Batchsending an empty batch results in error 400

Offline

Board footer

Powered by FluxBB