Skip to content

Commit 4c8e88a

Browse files
committed
Add test to verify #1759
1 parent 83c3f0c commit 4c8e88a

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

test/unit/helpers/bulk.test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ test('bulk delete', t => {
10701070
const [{ port }, server] = await buildServer(handler)
10711071
const client = new Client({ node: `http://localhost:${port}` })
10721072
let id = 0
1073+
10731074
const result = await client.helpers.bulk({
10741075
datasource: dataset.slice(),
10751076
flushBytes: 1,
@@ -1106,6 +1107,70 @@ test('bulk delete', t => {
11061107
server.stop()
11071108
})
11081109

1110+
t.test('Should call onDrop on the correct document when doing a mix of operations that includes deletes', async t => {
1111+
// checks to ensure onDrop doesn't provide the wrong document when some operations are deletes
1112+
// see https://github.com/elastic/elasticsearch-js/issues/1751
1113+
async function handler (req: http.IncomingMessage, res: http.ServerResponse) {
1114+
res.setHeader('content-type', 'application/json')
1115+
res.end(JSON.stringify({
1116+
took: 0,
1117+
errors: true,
1118+
items: [
1119+
{ delete: { status: 200 } },
1120+
{ index: { status: 429 } },
1121+
{ index: { status: 200 } }
1122+
]
1123+
}))
1124+
}
1125+
1126+
const [{ port }, server] = await buildServer(handler)
1127+
const client = new Client({ node: `http://localhost:${port}` })
1128+
let counter = 0
1129+
const result = await client.helpers.bulk({
1130+
datasource: dataset.slice(),
1131+
concurrency: 1,
1132+
wait: 10,
1133+
retries: 0,
1134+
onDocument (doc) {
1135+
counter++
1136+
if (counter === 1) {
1137+
return {
1138+
delete: {
1139+
_index: 'test',
1140+
_id: String(counter)
1141+
}
1142+
}
1143+
} else {
1144+
return {
1145+
index: {
1146+
_index: 'test',
1147+
}
1148+
}
1149+
}
1150+
},
1151+
onDrop (doc) {
1152+
t.same(doc, {
1153+
status: 429,
1154+
error: null,
1155+
operation: { index: { _index: 'test' } },
1156+
document: { user: "arya", age: 18 },
1157+
retried: false,
1158+
})
1159+
}
1160+
})
1161+
1162+
t.type(result.time, 'number')
1163+
t.type(result.bytes, 'number')
1164+
t.match(result, {
1165+
total: 3,
1166+
successful: 2,
1167+
retry: 0,
1168+
failed: 1,
1169+
aborted: false
1170+
})
1171+
server.stop()
1172+
})
1173+
11091174
t.end()
11101175
})
11111176

0 commit comments

Comments
 (0)