#!/bin/bash

cvmfs_test_name="Traverse sft.cern.ch with normal-size cache"

cvmfs_run_test() {
  logfile=$1

  # This test is related to 026-tightcache and CVM-1742. In contrast to
  # the tight cache test, we here test accumulation of many small catalogs,
  # which should not make the client run out of fds.

  cvmfs_mount "sft.cern.ch" \
    "CVMFS_QUOTA_LIMIT=10000" \
    "CVMFS_NFILES=2000" \
    "CVMFS_CHECK_PERMISSIONS=no" \
    "CVMFS_AUTO_UPDATE=no" || return 1

  echo "Finding things in /cvmfs/sft.cern.ch"
  sudo find /cvmfs/sft.cern.ch/lcg/releases/ -ignore_readdir_race -maxdepth 4 -type 'd' -not -perm -a+r > /dev/null
  local retval=$?
  if [ $retval -ne 0 ]; then
    echo "retval $retval"
    return 2
  fi

  local num_detach=$(sudo cvmfs_talk -i sft.cern.ch internal affairs | \
    grep ^catalog_mgr.n_detach_siblings | cut -f2 -d\|)
  echo "*** number of catalog detachs: $num_detach"
  [ x"$num_detach" != x"" ] || return 10
  if [ $num_detach -le 0 ]; then
    return 11
  fi

  return 0
}
