# Test 1: Test that shared connections are timed out
#
-NOW=`date +%s`
-echo "Create shared connection towards remote LDAP (time_t now=$NOW timeout=`expr $NOW + $TIMEOUT`)"
+CONN_BEGINS=`date +%s`
+CONN_EXPIRES=`expr $CONN_BEGINS + $TIMEOUT`
+echo "Create shared connection towards remote LDAP (time_t now=$CONN_BEGINS timeout=$CONN_EXPIRES)"
$LDAPSEARCH -b "dc=idle-timeout,$BASEDN" \
-D "cn=Manager,dc=local,dc=com" \
# Check that connections are established by searching for olmDbConnURI from Monitor
-echo "Checking that proxy has created connections towards backend"
+echo "Checking that proxy has created connections towards backend (time_t now=`date +%s`)"
$LDAPSEARCH -b "cn=Connections,cn=database 2,cn=databases,cn=monitor" -s one -LLL olmDbConnURI \
-D "cn=Manager,dc=local,dc=com" \
# Wait for connections to be closed, either due to
# - idle-timeout and
# - conn-ttl
-
+# sleep 2 second overtime for robustness of the test case
echo "Sleeping until idle-timeout and conn-ttl have passed"
-sleep `expr $TIMEOUT + 1`
+NOW=`date +%s`
+sleep `expr $CONN_EXPIRES - $NOW + 2`
echo "Checking that proxy has closed expired connections towards the remote LDAP server (time_t now=`date +%s`)"
# Test 2: Test that private connections are timed out
#
-NOW=`date +%s`
-echo "Create private connection towards remote LDAP (time_t now=$NOW timeout=`expr $NOW + $TIMEOUT`)"
+CONN_BEGINS=`date +%s`
+CONN_EXPIRES=`expr $CONN_BEGINS + $TIMEOUT`
+echo "Create private connection towards remote LDAP (time_t now=$CONN_BEGINS timeout=$CONN_EXPIRES)"
# Create fifos that are used to pass searches from the test case to ldapsearch
rm -f $TESTDIR/ldapsearch1.fifo $TESTDIR/ldapsearch2.fifo
# Trigger LDAP connections towards the proxy by executing a search
echo 'objectclass=*' >&3
echo 'objectclass=*' >&4
-sleep 1
-echo "Checking that proxy has created connections towards backend"
+# wait for ldapsearches (running as background processes) to execute search operations
+sleep 2
+
+echo "Checking that proxy has created connections towards backend (time_t now=`date +%s`)"
$LDAPSEARCH -b "cn=Connections,cn=database 2,cn=databases,cn=monitor" -s one -LLL olmDbConnURI \
-D "cn=Manager,dc=local,dc=com" \
exit $RC
fi
-
+# Wait for connections to be closed, either due to
+# - idle-timeout and
+# - conn-ttl
+# sleep 2 second overtime for robustness of the test case
echo "Sleeping until idle-timeout and conn-ttl have passed"
-sleep `expr $TIMEOUT + 1`
+NOW=`date +%s`
+sleep `expr $CONN_EXPIRES - $NOW + 2`
echo "Checking that proxy has closed expired connections towards the remote LDAP server (time_t now=`date +%s`)"
#
echo "Checking that idle-timeout is reset on activity"
-NOW=`date +%s`
-echo "Create cached connection: idle-timeout timeout starts (time_t now=$NOW, original_timeout=`expr $NOW + $TIMEOUT`)"
+CONN_BEGINS=`date +%s`
+CONN_EXPIRES=`expr $CONN_BEGINS + $TIMEOUT`
+echo "Create cached connection: idle-timeout timeout starts (time_t now=$CONN_BEGINS, original_timeout=$CONN_EXPIRES)"
$LDAPSEARCH -b "dc=idle-timeout,$BASEDN" \
-D "cn=Manager,dc=local,dc=com" \
-H $URI2 \
exit $RC
fi
-# sleep second less than idle-timeout to extend the timeout
-sleep `expr $TIMEOUT - 1`
+# sleep until 2 seconds before idle-timeout, then extend the timeout by executing another search operation
NOW=`date +%s`
-echo "Do another search to reset the timeout (time_t now=$NOW, new_timeout=`expr $NOW + $TIMEOUT`)"
+sleep `expr $CONN_EXPIRES - $NOW - 2`
+
+CONN_BEGINS=`date +%s`
+CONN_EXPIRES=`expr $CONN_BEGINS + $TIMEOUT`
+echo "Do another search to reset the timeout (time_t now=$CONN_BEGINS, new_timeout=$CONN_EXPIRES)"
$LDAPSEARCH -b "dc=idle-timeout,$BASEDN" \
-D "cn=Manager,dc=local,dc=com" \
-H $URI2 \
exit $RC
fi
-sleep `expr $TIMEOUT - 1`
+# sleep until 2 seconds before new exteneded idle-timeout, check that connection still exist
+NOW=`date +%s`
+sleep `expr $CONN_EXPIRES - $NOW - 2`
echo "Check that connection is still alive due to idle-timeout reset (time_t now=`date +%s`)"
$LDAPSEARCH -b "cn=Connections,cn=database 2,cn=databases,cn=monitor" -s one -LLL olmDbConnURI \
-D "cn=Manager,dc=local,dc=com" \
exit $RC
fi
-sleep 2
+# sleep until 2 seconds after timeout, check that connection does not exist
+NOW=`date +%s`
+sleep `expr $CONN_EXPIRES - $NOW + 2`
echo "Check that connection is closed after extended idle-timeout has passed (time_t now=`date +%s`)"
$LDAPSEARCH -b "cn=Connections,cn=database 2,cn=databases,cn=monitor" -s one -LLL olmDbConnURI \
-D "cn=Manager,dc=local,dc=com" \
exit $RC
fi
-
test $KILLSERVERS != no && kill -HUP $KILLPIDS
echo ">>>>> Test succeeded"