3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2011 The OpenLDAP Foundation.
6 ## All rights reserved.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
16 # This script tests race conditions related to setting up the syncrepl
17 # refresh phase, especially when the provider is itself a consumer
18 # refreshing from its provider again.
20 # The configuration used is a provider->forwarder->consumer chain, where
21 # the forwarder is restarted between add/delete of entries on the provider.
23 echo "Running defines.sh"
24 . $SRCDIR/scripts/defines.sh
26 test "x$INITIATION_RACE_TESTS" = "x" && INITIATION_RACE_TESTS=1
28 if test $SYNCPROV = syncprovno; then
29 echo "Syncrepl provider overlay not available, test skipped"
35 PROV_DIR=$TESTDIR/prov
36 CONS_DIR=$TESTDIR/cons
37 FWD1_DIR=$TESTDIR/fwd1
38 FWD2_DIR=$TESTDIR/fwd2
48 DIRS="$PROV_DIR $CONS_DIR $FWD1_DIR"
49 URIS="$PROV_URI $CONS_URI $FWD1_URI"
52 nullExclude="" nullOK=""
53 test $BACKEND = null && nullExclude="# " nullOK="OK" noObj=0
58 mkdir -p $dir $dir/slapd.d $dir/db
63 $SLAPPASSWD -g -n >$CONFIGPWF
66 bdb|hdb) olcDbCheckpoint="olcDbCheckpoint";;
67 *) olcDbCheckpoint="# olcDbCheckpoint";;
70 echo "Initializing server configurations"
72 $SLAPADD -F $dir/slapd.d -n 0 <<EOF
74 objectClass: olcGlobal
76 olcServerID: 1 $PROV_URI
77 olcServerID: 2 $CONS_URI
78 olcServerID: 3 $FWD1_URI
80 dn: olcDatabase={0}config,cn=config
81 objectClass: olcDatabaseConfig
82 olcDatabase: {0}config
83 olcRootPW:< file://$CONFIGPWF
88 echo "Starting provider slapd on $PROV_URI"
90 $SLAPD -F slapd.d -h $PROV_URI -d $LVL $TIMING >> $PROV_LOG 2>&1 &
92 if test $WAIT != 0 ; then
96 KILLPIDS="$KILLPIDS $PROV_PID"
99 for i in 1 2 3 4 5; do
100 $LDAPSEARCH -s base -b "" -H $PROV_URI \
101 'objectclass=*' > /dev/null 2>&1
103 test $RC = 0 && break
104 echo "Waiting $i seconds for slapd to start..."
107 if test $RC != 0 ; then
108 echo "ldapsearch failed ($RC)!"
109 test $KILLSERVERS != no && kill -HUP $KILLPIDS
113 echo "Starting forward1 slapd on $FWD1_URI"
115 $SLAPD -F slapd.d -h $FWD1_URI -d $LVL $TIMING >> $FWD1_LOG 2>&1 &
117 if test $WAIT != 0 ; then
121 KILLPIDS="$KILLPIDS $FWD1_PID"
124 for i in 1 2 3 4 5; do
125 $LDAPSEARCH -s base -b "" -H $FWD1_URI \
126 'objectclass=*' > /dev/null 2>&1
128 test $RC = 0 && break
129 echo "Waiting $i seconds for slapd to start..."
132 if test $RC != 0 ; then
133 echo "ldapsearch failed ($RC)!"
134 test $KILLSERVERS != no && kill -HUP $KILLPIDS
138 echo "Starting consumer slapd on $CONS_URI"
140 $SLAPD -F slapd.d -h $CONS_URI -d $LVL $TIMING >> $CONS_LOG 2>&1 &
142 if test $WAIT != 0 ; then
146 KILLPIDS="$KILLPIDS $CONS_PID"
149 for i in 1 2 3 4 5; do
150 $LDAPSEARCH -s base -b "" -H $CONS_URI \
151 'objectclass=*' > /dev/null 2>&1
153 test $RC = 0 && break
154 echo "Waiting $i seconds for slapd to start..."
157 if test $RC != 0 ; then
158 echo "ldapsearch failed ($RC)!"
159 test $KILLSERVERS != no && kill -HUP $KILLPIDS
164 echo "Adding schema on $uri"
165 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
166 include: file://$ABS_SCHEMADIR/core.ldif
168 include: file://$ABS_SCHEMADIR/cosine.ldif
170 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
172 include: file://$ABS_SCHEMADIR/openldap.ldif
174 include: file://$ABS_SCHEMADIR/nis.ldif
178 if test $RC != 0 ; then
179 echo "ldapadd failed ($RC)!"
180 test $KILLSERVERS != no && kill -HUP $KILLPIDS
184 [ "$BACKENDTYPE" = mod ] || continue
186 echo "Adding backend module on $uri..."
187 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
188 dn: cn=module,cn=config
189 objectClass: olcModuleList
191 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
192 olcModuleLoad: back_$BACKEND.la
196 if test $RC != 0 ; then
197 echo "ldapadd failed for backend module ($RC)!"
198 test $KILLSERVERS != no && kill -HUP $KILLPIDS
204 [ "$AC_syncprov" = syncprovmod ] && syncprov_module="
205 dn: cn=module,cn=config
206 objectClass: olcModuleList
208 olcModulePath: $TESTWD/../servers/slapd/overlays
209 olcModuleLoad: syncprov.la"
211 for uri in $PROV_URI; do
212 echo "Adding database configuration on $uri"
213 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
214 dn: olcDatabase={1}$BACKEND,cn=config
215 objectClass: olcDatabaseConfig
216 objectClass: olc${BACKEND}Config
217 olcDatabase: {1}$BACKEND
218 ${nullExclude}olcDbDirectory: ./db
219 $olcDbCheckpoint: 1024 5
221 olcRootDN: $MANAGERDN
226 dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
227 objectClass: olcOverlayConfig
228 objectClass: olcSyncProvConfig
229 olcOverlay: {0}syncprov
234 if test $RC != 0 ; then
235 echo "ldapadd failed ($RC)!"
236 test $KILLSERVERS != no && kill -HUP $KILLPIDS
240 echo "Populating provider on $uri"
241 $LDAPADD -D "$MANAGERDN" -H $PROV_URI -w $PASSWD <<EOF >> $TESTOUT 2>&1
244 objectClass: organization
245 objectClass: dcObject
251 if test $RC != 0 ; then
252 echo "ldapadd failed ($RC)!"
253 test $KILLSERVERS != no && kill -HUP $KILLPIDS
258 for uri in $FWD1_URI; do
259 echo "Adding database configuration on $uri"
260 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
261 dn: olcDatabase={1}$BACKEND,cn=config
262 objectClass: olcDatabaseConfig
263 objectClass: olc${BACKEND}Config
264 olcDatabase: {1}$BACKEND
265 ${nullExclude}olcDbDirectory: ./db
266 $olcDbCheckpoint: 1024 5
268 olcRootDN: $MANAGERDN
270 olcSyncRepl: rid=1 provider=$PROV_URI searchbase="$BASEDN"
271 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
272 type=refreshAndPersist retry="$RETRY" timeout=1
276 dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
277 objectClass: olcOverlayConfig
278 objectClass: olcSyncProvConfig
279 olcOverlay: {0}syncprov
284 if test $RC != 0 ; then
285 echo "ldapadd failed ($RC)!"
286 test $KILLSERVERS != no && kill -HUP $KILLPIDS
291 for uri in $CONS_URI; do
292 echo "Adding database configuration on $uri"
293 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
294 dn: olcDatabase={1}$BACKEND,cn=config
295 objectClass: olcDatabaseConfig
296 objectClass: olc${BACKEND}Config
297 olcDatabase: {1}$BACKEND
298 ${nullExclude}olcDbDirectory: ./db
299 $olcDbCheckpoint: 1024 5
301 olcRootDN: $MANAGERDN
303 olcSyncRepl: rid=1 provider=$FWD1_URI searchbase="$BASEDN"
304 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
305 type=refreshAndPersist retry="$RETRY" timeout=1
309 if test $RC != 0 ; then
310 echo "ldapadd failed ($RC)!"
311 test $KILLSERVERS != no && kill -HUP $KILLPIDS
316 for uri in $FWD1_URI $CONS_URI; do
317 echo "Using ldapsearch to check that $uri received database..."
318 for i in 1 2 3 4 5; do
319 $LDAPSEARCH -s base -b "$BASEDN" -H $uri \
320 'objectclass=*' > /dev/null 2>&1
322 test $RC = 0 && break
323 echo "Waiting $i seconds for slapd to receive database..."
326 if test $RC != 0 ; then
327 echo "ldapsearch failed ($RC)!"
328 test $KILLSERVERS != no && kill -HUP $KILLPIDS
344 while test $ERROR -eq 0 -a $RACE_NUM -lt $INITIATION_RACE_TESTS ; do
345 RACE_NUM=`expr $RACE_NUM + 1`
346 echo "Running $RACE_NUM of $INITIATION_RACE_TESTS syncrepl initiation race tests..."
348 echo "Stopping forwarders for add test"
349 for pid in $FWD1_PID; do
352 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $pid / /"`;
356 addEnd=`expr $addEnd + $nEntries`
358 echo "Using ldapadd to add $nEntries entries on provider"
359 while test $addIdx -lt $addEnd; do
360 $LDAPADD -D "$MANAGERDN" -H $PROV_URI -w $PASSWD <<EOF >> $TESTOUT 2>&1
361 dn: ou=$addIdx,$BASEDN
363 objectClass: organizationalUnit
368 if test $RC != 0 ; then
369 echo "ldapadd failed for entry $addIdx ($RC)!"
370 test $KILLSERVERS != no && kill -HUP $KILLPIDS
373 addIdx=`expr $addIdx + 1`
376 echo "Starting forwarders again"
378 $SLAPD -F slapd.d -h $FWD1_URI -d $LVL $TIMING >> $FWD1_LOG 2>&1 &
380 KILLPIDS="$KILLPIDS $FWD1_PID"
383 addEnd=`expr $addEnd + $nEntries`
385 echo "Using ldapadd to add $nEntries more entries on provider"
386 while test $addIdx -lt $addEnd; do
387 $LDAPADD -D "$MANAGERDN" -H $PROV_URI -w $PASSWD <<EOF >> $TESTOUT 2>&1
388 dn: ou=$addIdx,$BASEDN
390 objectClass: organizationalUnit
395 if test $RC != 0 ; then
396 echo "ldapadd failed for entry $addIdx ($RC)!"
397 test $KILLSERVERS != no && kill -HUP $KILLPIDS
400 addIdx=`expr $addIdx + 1`
403 for uri in $FWD1_URI $CONS_URI; do
404 echo "Checking replication to $uri"
407 while test $i -lt $addEnd; do
408 for j in 1 2 3 4 5; do
409 RESULT=`$LDAPSEARCH -H $uri -s base -b "ou=$i,$BASEDN" 2>&1 \
410 | awk '/^dn:/ {print "OK"}'`
411 if test "x$RESULT$nullOK" = "xOK" ; then
415 echo "Waiting $j seconds for $uri to receive entry $i..."
418 if test $RC != 0 ; then
419 echo "ERROR: Entry $i not replicated to $uri! ($RC)!"
425 if test $ERROR != 0; then break; fi
427 if test $ERROR != 0; then break; fi
429 echo "Stopping forwarders for add/delete test"
430 for pid in $FWD1_PID; do
433 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $pid / /"`;
437 addEnd=`expr $addEnd + $nEntries`
439 echo "Using ldapadd to add $nEntries entries on provider"
440 while test $addIdx -lt $addEnd; do
441 $LDAPADD -D "$MANAGERDN" -H $PROV_URI -w $PASSWD <<EOF >> $TESTOUT 2>&1
442 dn: ou=$addIdx,$BASEDN
444 objectClass: organizationalUnit
449 if test $RC != 0 ; then
450 echo "ldapadd failed for entry $addIdx ($RC)!"
451 test $KILLSERVERS != no && kill -HUP $KILLPIDS
454 addIdx=`expr $addIdx + 1`
458 delEnd=`expr $delEnd + $nEntries`
460 echo "Using ldapdelete to delete $nEntries entries on provider"
461 while test $delIdx -lt $delEnd; do
462 $LDAPDELETE -D "$MANAGERDN" -H $PROV_URI -w $PASSWD "ou=$delIdx,$BASEDN"
464 if test $RC != 0 ; then
465 echo "ldapdelete failed ($RC)!"
466 test $KILLSERVERS != no && kill -HUP $KILLPIDS
469 delIdx=`expr $delIdx + 1`
472 echo "Starting forwarders again"
474 $SLAPD -F slapd.d -h $FWD1_URI -d $LVL $TIMING >> $FWD1_LOG 2>&1 &
476 KILLPIDS="$KILLPIDS $FWD1_PID"
479 addEnd=`expr $addEnd + $nEntries`
480 delEnd=`expr $delEnd + $nEntries`
482 echo "Using ldapadd to add $nEntries more entries on provider"
483 while test $addIdx -lt $addEnd; do
484 $LDAPADD -D "$MANAGERDN" -H $PROV_URI -w $PASSWD <<EOF >> $TESTOUT 2>&1
485 dn: ou=$addIdx,$BASEDN
487 objectClass: organizationalUnit
492 if test $RC != 0 ; then
493 echo "ldapadd failed for entry $addIdx ($RC)!"
494 test $KILLSERVERS != no && kill -HUP $KILLPIDS
497 addIdx=`expr $addIdx + 1`
500 echo "Using ldapdelete to delete $nEntries more entries on provider"
501 while test $delIdx -lt $delEnd; do
502 $LDAPDELETE -D "$MANAGERDN" -H $PROV_URI -w $PASSWD "ou=$delIdx,$BASEDN"
504 if test $RC != 0 ; then
505 echo "ldapdelete failed ($RC)!"
506 test $KILLSERVERS != no && kill -HUP $KILLPIDS
509 delIdx=`expr $delIdx + 1`
512 for uri in $FWD1_URI $CONS_URI; do
513 echo "Checking replication to $uri"
516 while test $i -lt $addEnd; do
517 for j in 1 2 3 4 5; do
518 RESULT=`$LDAPSEARCH -H $uri -s base -b "ou=$i,$BASEDN" 2>&1 \
519 | awk '/^dn:/ {print "OK"}'`
520 if test "x$RESULT$nullOK" = "xOK" ; then
524 echo "Waiting $j seconds for $uri to receive entry $i..."
527 if test $RC != 0 ; then
528 echo "ERROR: Entry $i not replicated to $uri! ($RC)!"
534 if test $ERROR != 0; then break; fi
537 while test $i -lt $delEnd; do
538 for j in 1 2 3 4 5; do
539 $LDAPSEARCH -s base -b "ou=$i,$BASEDN" -H $uri > /dev/null 2>&1
541 if test $RC = $noObj; then break; fi
542 echo "Waiting $j seconds for $uri to delete entry $i..."
545 if test $RC != $noObj; then
546 echo "ERROR: Entry $i not removed on $uri! (RC=$RC)"
552 if test $ERROR != 0; then break; fi
554 if test $ERROR != 0; then break; fi
556 echo "Stopping forwarders for delete test"
557 for pid in $FWD1_PID; do
560 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $pid / /"`;
564 delEnd=`expr $delEnd + $nEntries`
566 echo "Using ldapdelete to delete entries on provider"
567 while test $delIdx -lt $delEnd; do
568 $LDAPDELETE -D "$MANAGERDN" -H $PROV_URI -w $PASSWD "ou=$delIdx,$BASEDN"
570 if test $RC != 0 ; then
571 echo "ldapdelete failed ($RC)!"
572 test $KILLSERVERS != no && kill -HUP $KILLPIDS
575 delIdx=`expr $delIdx + 1`
578 echo "Starting forwarders again"
580 $SLAPD -F slapd.d -h $FWD1_URI -d $LVL $TIMING >> $FWD1_LOG 2>&1 &
582 KILLPIDS="$KILLPIDS $FWD1_PID"
585 delEnd=`expr $delEnd + $nEntries`
587 echo "Using ldapdelete to delete $nEntries more entries on provider"
588 while test $delIdx -lt $delEnd; do
589 $LDAPDELETE -D "$MANAGERDN" -H $PROV_URI -w $PASSWD "ou=$delIdx,$BASEDN"
591 if test $RC != 0 ; then
592 echo "ldapdelete failed ($RC)!"
593 test $KILLSERVERS != no && kill -HUP $KILLPIDS
596 delIdx=`expr $delIdx + 1`
599 for uri in $FWD1_URI $CONS_URI; do
600 echo "Checking replication to $uri"
603 while test $i -lt $delEnd; do
604 for j in 1 2 3 4 5; do
605 $LDAPSEARCH -s base -b "ou=$i,$BASEDN" -H $uri > /dev/null 2>&1
607 if test $RC = $noObj; then break; fi
608 echo "Waiting $j seconds for $uri to delete entry $i..."
611 if test $RC != $noObj; then
612 echo "ERROR: Entry $i not removed on $uri! (RC=$RC)"
618 if test $ERROR != 0; then break; fi
620 if test $ERROR != 0; then break; fi
622 echo "Checking contextCSN"
624 CSN1=`$LDAPSEARCH -H $URI1 -b $BASEDN -s base contextCSN | grep contextCSN`
625 CSN2=`$LDAPSEARCH -H $URI2 -b $BASEDN -s base contextCSN | grep contextCSN`
626 CSN3=`$LDAPSEARCH -H $URI3 -b $BASEDN -s base contextCSN | grep contextCSN`
628 if test -z "$CSN1" ; then
629 test $BACKEND = null && break
630 echo "ERROR: contextCSN empty on provider"
634 nCSN=`echo "$CSN1" | wc -l`
635 if test "$nCSN" -ne 1 ; then
636 echo "ERROR: Wrong contextCSN count on provder, should be 1"
638 test $KILLSERVERS != no && kill -HUP $KILLPIDS
641 if test -z "$CSN2" -o "$CSN1" != "$CSN2" ; then
642 echo "ERROR: contextCSN mismatch between provider and consumer"
643 echo "contextCSN on provider: $CSN1"
644 echo "contextCSN on consumer: $CSN2"
648 if test -z "$CSN3" -o "$CSN1" != "$CSN3" ; then
649 echo "ERROR: contextCSN mismatch between provider and forward1"
650 echo "contextCSN on provider: $CSN1"
651 echo "contextCSN on forward1: $CSN3"
657 test $KILLSERVERS != no && kill -HUP $KILLPIDS
659 if test $ERROR != 0; then
660 echo "Error found after $RACE_NUM of $INITIATION_RACE_TESTS iterations"
663 echo "No race errors found after $INITIATION_RACE_TESTS iterations"
666 echo ">>>>> Test succeeded"