#!/usr/bin/env bash

echo -en "\tFinished loading to index at "
date

suffix=$suffix docker-compose -f ../../docker-compose.yml --env-file ../../.env restart manticoresearch

if timeout 30 grep -m2 '\[BUDDY\] started' <(docker logs -f manticoresearch_engine) > /dev/null; then
  echo -e '\tAccepting connections';
else
  echo -e '\tManticore failed to start properly in 60 seconds';
  exit 1
fi

inserted=$(docker exec manticoresearch_engine mysql -h0 -P9306 -e "SELECT count(*) FROM $test\G" | grep count | cut -d" " -f2)
echo -e "\tCount of inserted documents: $inserted"

if [[ ! $inserted -eq 1165439 ]]; then
  echo "Inserted count mismatch"
  exit 1
fi
