Optimize number of round-trip HTTP connections made by the client by having the submit handler return metadata about whether there are pending dump/deletion requests

For now, I'm still keeping the dedicated endpoints for those functionalities, but since most of the time there are no dump/deletion requests this should cut down the number of requests made by the client by 2/3.
This commit is contained in:
David Dworken
2023-09-21 11:35:24 -07:00
parent b05fb0f818
commit 1e43de689f
10 changed files with 156 additions and 63 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"os/exec"
@@ -937,11 +938,22 @@ func manuallySubmitHistoryEntry(t testing.TB, userSecret string, entry data.Hist
}
jsonValue, err := json.Marshal([]shared.EncHistoryEntry{encEntry})
testutils.Check(t, err)
resp, err := http.Post("http://localhost:8080/api/v1/submit", "application/json", bytes.NewBuffer(jsonValue))
require.NotEqual(t, "", entry.DeviceId)
resp, err := http.Post("http://localhost:8080/api/v1/submit?source_device_id="+entry.DeviceId, "application/json", bytes.NewBuffer(jsonValue))
testutils.Check(t, err)
if resp.StatusCode != 200 {
t.Fatalf("failed to submit result to backend, status_code=%d", resp.StatusCode)
}
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("failed to read resp.Body: %v", err)
}
submitResp := shared.SubmitResponse{}
err = json.Unmarshal(respBody, &submitResp)
if err != nil {
t.Fatalf("failed to deserialize SubmitResponse: %v", err)
}
}
func testTimestampsAreReasonablyCorrect(t *testing.T, tester shellTester) {