Skip to content

Commit 025c6ef

Browse files
committed
fix: assertion
1 parent ae16372 commit 025c6ef

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

scripts/cts/testServer/replaceAllObjectsWithTransformation.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const raowtState: Record<
1212
copyCount: number;
1313
deleteCount: number;
1414
pushCount: number;
15+
getEventCount: number;
1516
tmpIndexName: string;
1617
waitTaskCount: number;
1718
waitingForFinalWaitTask: boolean;
@@ -42,9 +43,10 @@ function addRoutes(app: Express): void {
4243
raowtState[lang] = {
4344
copyCount: 0,
4445
pushCount: 0,
46+
getEventCount: 0,
4547
deleteCount: 1,
4648
waitTaskCount: 0,
47-
tmpIndexName: req.body.destination,
49+
tmpIndexName: req.params.indexName,
4850
waitingForFinalWaitTask: false,
4951
successful: false,
5052
};
@@ -69,6 +71,7 @@ function addRoutes(app: Express): void {
6971
raowtState[lang] = {
7072
copyCount: 1,
7173
pushCount: 0,
74+
getEventCount: 0,
7275
deleteCount: 0,
7376
waitTaskCount: 0,
7477
tmpIndexName: req.body.destination,
@@ -89,6 +92,7 @@ function addRoutes(app: Express): void {
8992
copyCount: 2,
9093
pushCount: 10,
9194
deleteCount: 0,
95+
getEventCount: 6,
9296
waitTaskCount: 2,
9397
tmpIndexName: req.params.indexName,
9498
waitingForFinalWaitTask: false,
@@ -121,18 +125,22 @@ function addRoutes(app: Express): void {
121125
raowtState[lang].pushCount += req.body.records.length;
122126

123127
res.json({
124-
runID: 'b1b7a982-524c-40d2-bb7f-48aab075abda',
128+
runID: `b1b7a982-524c-40d2-bb7f-48aab075abda_${lang}`,
125129
eventID: `113b2068-6337-4c85-b5c2-e7b213d8292${raowtState[lang].pushCount}`,
126130
message: 'OK',
127131
createdAt: '2022-05-12T06:24:30.049Z',
128132
});
129133
});
130134

131135
app.get('/1/runs/:runID/events/:eventID', (req, res) => {
136+
const lang = req.params.runID.match(/^b1b7a982-524c-40d2-bb7f-48aab075abda_(.*)$/)?.[1] as string;
137+
138+
raowtState[lang].getEventCount++;
139+
132140
res.json({
133141
status: 'succeeded',
134-
eventID: '113b2068-6337-4c85-b5c2-e7b213d82921',
135-
runID: 'b1b7a982-524c-40d2-bb7f-48aab075abda',
142+
eventID: req.params.eventID,
143+
runID: req.params.runID,
136144
type: 'fetch',
137145
batchSize: 1,
138146
publishedAt: '2022-05-12T06:24:30.049Z',
@@ -152,6 +160,7 @@ function addRoutes(app: Express): void {
152160
expect(raowtState[lang]).to.deep.equal({
153161
copyCount: 2,
154162
pushCount: 10,
163+
getEventCount: 6,
155164
deleteCount: 0,
156165
waitTaskCount: 3,
157166
tmpIndexName: req.params.indexName,

templates/java/api_helpers.mustache

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ public <T> List<WatchResponse> chunkedPush(
4949
waitBatchSize = batchSize;
5050
}
5151

52-
for (T item : objects) {
53-
if (records.size() == batchSize || !item.hasNext()) {
52+
Iterator<T> it = objects.iterator();
53+
54+
while (true) {
55+
if (records.size() == batchSize || !it.hasNext()) {
5456
WatchResponse watch =
5557
this.push(
5658
indexName,
@@ -63,9 +65,9 @@ public <T> List<WatchResponse> chunkedPush(
6365
records.clear();
6466
}
6567

66-
records.add(item);
68+
records.add(it);
6769

68-
if (waitForTasks && (responses.size() % waitBatchSize == 0 || !item.hasNext())) {
70+
if (waitForTasks && (responses.size() % waitBatchSize == 0 || !it.hasNext())) {
6971
responses.subList(Math.max(responses.size() - waitBatchSize, 0), responses.size()).forEach(response -> {
7072
TaskUtils.retryUntil(
7173
() -> {
@@ -88,6 +90,10 @@ public <T> List<WatchResponse> chunkedPush(
8890
}
8991
);
9092
}
93+
94+
if (!it.hasNext()) {
95+
break;
96+
}
9197
}
9298

9399
return responses;

templates/php/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ use Algolia\AlgoliaSearch\Exceptions\NotFoundException;
356356
if ($waitForTasks && (0 === count($responses) % $waitBatchSize || $count === sizeof($objects) - 1)) {
357357
$timeoutCalculation = 'Algolia\AlgoliaSearch\Support\Helpers::linearTimeout';
358358
359-
foreach (array_slice($responses, -waitBatchSize) as $response) {
359+
foreach (array_slice($responses, -$waitBatchSize) as $response) {
360360
$retry = 0;
361361
362362
while ($retry < 50) {

tests/CTS/client/search/replaceAllObjectsWithTransformation.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,25 @@
7474
},
7575
"watchResponses": [
7676
{
77-
"runID": "b1b7a982-524c-40d2-bb7f-48aab075abda",
77+
"runID": "b1b7a982-524c-40d2-bb7f-48aab075abda_${{language}}",
7878
"eventID": "113b2068-6337-4c85-b5c2-e7b213d82923",
7979
"message": "OK",
8080
"createdAt": "2022-05-12T06:24:30.049Z"
8181
},
8282
{
83-
"runID": "b1b7a982-524c-40d2-bb7f-48aab075abda",
83+
"runID": "b1b7a982-524c-40d2-bb7f-48aab075abda_${{language}}",
8484
"eventID": "113b2068-6337-4c85-b5c2-e7b213d82926",
8585
"message": "OK",
8686
"createdAt": "2022-05-12T06:24:30.049Z"
8787
},
8888
{
89-
"runID": "b1b7a982-524c-40d2-bb7f-48aab075abda",
89+
"runID": "b1b7a982-524c-40d2-bb7f-48aab075abda_${{language}}",
9090
"eventID": "113b2068-6337-4c85-b5c2-e7b213d82929",
9191
"message": "OK",
9292
"createdAt": "2022-05-12T06:24:30.049Z"
9393
},
9494
{
95-
"runID": "b1b7a982-524c-40d2-bb7f-48aab075abda",
95+
"runID": "b1b7a982-524c-40d2-bb7f-48aab075abda_${{language}}",
9696
"eventID": "113b2068-6337-4c85-b5c2-e7b213d829210",
9797
"message": "OK",
9898
"createdAt": "2022-05-12T06:24:30.049Z"

0 commit comments

Comments
 (0)