Skip to content

Commit 0ad3e79

Browse files
committed
chore(ci): add a test case for empty file check
- empty files are not counted in eligible files Signed-off-by: kyteinsky <kyteinsky@gmail.com>
1 parent b8b4a2c commit 0ad3e79

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

.github/workflows/integration-test.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,103 @@ jobs:
346346
echo "$OUT2" | grep -q "If all of these points are met, we give a Green label." || exit 1
347347
echo ::endgroup::
348348
349+
- name: Wait for files queue to drain to zero
350+
run: |
351+
echo "::group::Waiting up to 5 minutes for documents queue to reach zero"
352+
for i in {1..30}; do
353+
stats=$(./occ context_chat:stats --json)
354+
scheduled=$(echo "$stats" | jq '[.queued_documents_counts | to_entries[].value] | add // 0')
355+
echo "Attempt $i: queued_documents=$scheduled"
356+
if [ "$scheduled" = "0" ]; then
357+
echo "Queue is empty"
358+
break
359+
fi
360+
if [ "$i" = "30" ]; then
361+
echo "Timeout: queue did not drain to zero (queued_documents=$scheduled)"
362+
exit 1
363+
fi
364+
sleep 10
365+
done
366+
echo "::endgroup::"
367+
368+
- name: Check if the empty files get identified, not indexed and don't cause any issues with the batch
369+
run: |
370+
NEW_FILES_COUNT=5
371+
372+
echo "::group::Stats before the empty files are added"
373+
prev_stats=$(./occ context_chat:stats --json)
374+
echo "$prev_stats"
375+
prev_scheduled=$(echo "$prev_stats" | jq '.queued_documents_counts.files__default // 0')
376+
prev_eligible=$(echo "$prev_stats" | jq '.eligible_files_count')
377+
prev_indexed=$(echo "$prev_stats" | jq '.vectordb_document_counts.files__default // 0')
378+
echo "queued_documents_counts.files__default before scan: $prev_scheduled"
379+
echo "::endgroup::"
380+
381+
# create empty markdown files in admin's home folder
382+
for i in $(seq 1 $NEW_FILES_COUNT); do
383+
touch "data/admin/files/test_empty_$i.md"
384+
done
385+
386+
# create one new file with content
387+
echo "hello world" > "data/admin/files/test_filled.md"
388+
389+
# run files scan so Nextcloud registers the new files
390+
./occ files:scan admin
391+
392+
echo "::group::Confirming new files appear in the queue after scan"
393+
stats=$(./occ context_chat:stats --json)
394+
echo "$stats"
395+
scheduled=$(echo "$stats" | jq '.queued_documents_counts.files__default // 0')
396+
echo "queued_documents_counts.files__default after scan: $scheduled"
397+
expected_scheduled=$((prev_scheduled + NEW_FILES_COUNT + 1)) # +1 non-empty file
398+
if [ "$scheduled" -ne "$expected_scheduled" ]; then
399+
echo "Error: expected exactly $expected_scheduled files in the queue (prev=$prev_scheduled + new=$NEW_FILES_COUNT), got $scheduled"
400+
exit 1
401+
fi
402+
echo "::endgroup::"
403+
404+
echo "::group::Waiting up to 5 minutes for queue to drain to zero again"
405+
for i in {1..30}; do
406+
stats=$(./occ context_chat:stats --json)
407+
scheduled=$(echo "$stats" | jq '[.queued_documents_counts | to_entries[].value] | add // 0')
408+
locked=$(echo "$stats" | jq '[.queued_documents_locked_counts | to_entries[].value] | add // 0')
409+
echo "Attempt $i: queued_documents=$scheduled locked=$locked"
410+
if [ "$scheduled" = "0" ]; then
411+
echo "Queue drained"
412+
break
413+
fi
414+
if [ "$i" = "30" ]; then
415+
echo "Timeout: queue did not drain to zero (queued_documents=$scheduled)"
416+
exit 1
417+
fi
418+
sleep 10
419+
done
420+
echo "::endgroup::"
421+
422+
# locked must be zero
423+
if [ "$locked" != "0" ]; then
424+
echo "Error: expected locked count to be 0, got $locked"
425+
exit 1
426+
fi
427+
echo "Locked count is 0 as expected"
428+
429+
# StorageService#countFiles filters size > 0, so empty files are NOT counted as eligible.
430+
# Only the 1 non-empty file is both eligible and indexed, so the gap must stay the same (diff=0).
431+
eligible=$(echo "$stats" | jq '.eligible_files_count')
432+
indexed=$(echo "$stats" | jq '.vectordb_document_counts.files__default // 0')
433+
echo "prev: eligible=$prev_eligible indexed=$prev_indexed"
434+
echo "eligible_files_count=$eligible vectordb_document_counts.files__default=$indexed"
435+
436+
prev_gap=$((prev_eligible - prev_indexed))
437+
curr_gap=$((eligible - indexed))
438+
gap_diff=$((curr_gap - prev_gap))
439+
echo "gap before=$prev_gap gap after=$curr_gap difference=$gap_diff expected=0"
440+
if [ "$gap_diff" -ne "0" ]; then
441+
echo "Error: expected the eligible-indexed gap to stay the same (empty files are excluded from eligible_files_count by the size > 0 filter), got diff=$gap_diff"
442+
exit 1
443+
fi
444+
echo "PASS: empty files excluded from eligible_files_count (size > 0 filter) and absent from vectordb_document_counts"
445+
349446
- name: Check python memory usage
350447
run: |
351448
ps -p $(cat pid.txt) -o pid,cmd,%mem,rss --sort=-%mem

0 commit comments

Comments
 (0)