xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test061-syncreplication-initiation (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
1d11b170bStron#! /bin/sh
2d11b170bStron# $OpenLDAP$
3d11b170bStron## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4d11b170bStron##
5*e670fd5cSchristos## Copyright 1998-2021 The OpenLDAP Foundation.
6d11b170bStron## All rights reserved.
7d11b170bStron##
8d11b170bStron## Redistribution and use in source and binary forms, with or without
9d11b170bStron## modification, are permitted only as authorized by the OpenLDAP
10d11b170bStron## Public License.
11d11b170bStron##
12d11b170bStron## A copy of this license is available in the file LICENSE in the
13d11b170bStron## top-level directory of the distribution or, alternatively, at
14d11b170bStron## <http://www.OpenLDAP.org/license.html>.
15d11b170bStron
16d11b170bStron# This script tests race conditions related to setting up the syncrepl
17d11b170bStron# refresh phase, especially when the provider is itself a consumer
18d11b170bStron# refreshing from its provider again.
19d11b170bStron
20d11b170bStron# The configuration used is a provider->forwarder->consumer chain, where
21d11b170bStron# the forwarder is restarted between add/delete of entries on the provider.
22d11b170bStron
23d11b170bStronecho "Running defines.sh"
24d11b170bStron. $SRCDIR/scripts/defines.sh
25d11b170bStron
26d11b170bStrontest "x$INITIATION_RACE_TESTS" = "x" && INITIATION_RACE_TESTS=1
27d11b170bStron
28d11b170bStronif test $SYNCPROV = syncprovno; then
29d11b170bStron	echo "Syncrepl provider overlay not available, test skipped"
30d11b170bStron	exit 0
31d11b170bStronfi
32d11b170bStron
33d11b170bStronRETRY="1 +"
34d11b170bStron
35d11b170bStronPROV_DIR=$TESTDIR/prov
36d11b170bStronCONS_DIR=$TESTDIR/cons
37d11b170bStronFWD1_DIR=$TESTDIR/fwd1
38d11b170bStronFWD2_DIR=$TESTDIR/fwd2
39d11b170bStron
40d11b170bStronPROV_URI=$URI1
41d11b170bStronCONS_URI=$URI2
42d11b170bStronFWD1_URI=$URI3
43d11b170bStron
44d11b170bStronPROV_LOG=$LOG1
45d11b170bStronCONS_LOG=$LOG2
46d11b170bStronFWD1_LOG=$LOG3
47d11b170bStron
48d11b170bStronDIRS="$PROV_DIR $CONS_DIR $FWD1_DIR"
49d11b170bStronURIS="$PROV_URI $CONS_URI $FWD1_URI"
50d11b170bStron
51d11b170bStronnoObj=32
52d11b170bStronnullExclude="" nullOK=""
53d11b170bStrontest $BACKEND = null && nullExclude="# " nullOK="OK" noObj=0
54d11b170bStron
55d11b170bStronmkdir -p $TESTDIR
56d11b170bStron
57d11b170bStronfor dir in $DIRS; do
58d11b170bStron	mkdir -p $dir $dir/slapd.d $dir/db
59d11b170bStrondone
60d11b170bStron
61d11b170bStronKILLPIDS=
62d11b170bStron
63d11b170bStron$SLAPPASSWD -g -n >$CONFIGPWF
64d11b170bStron
65d11b170bStroncase "$BACKEND" in
66d11b170bStron	*)		olcDbCheckpoint="# olcDbCheckpoint";;
67d11b170bStronesac
68d11b170bStron
69d11b170bStronecho "Initializing server configurations"
70d11b170bStronfor dir in $DIRS; do
71d11b170bStron	$SLAPADD -F $dir/slapd.d -n 0 <<EOF
72d11b170bStrondn: cn=config
73d11b170bStronobjectClass: olcGlobal
74d11b170bStroncn: config
75d11b170bStronolcServerID: 1 $PROV_URI
76d11b170bStronolcServerID: 2 $CONS_URI
77d11b170bStronolcServerID: 3 $FWD1_URI
78d11b170bStron
79d11b170bStrondn: olcDatabase={0}config,cn=config
80d11b170bStronobjectClass: olcDatabaseConfig
81d11b170bStronolcDatabase: {0}config
82d11b170bStronolcRootPW:< file://$CONFIGPWF
83d11b170bStron
84d11b170bStronEOF
85d11b170bStrondone
86d11b170bStron
87d11b170bStronecho "Starting provider slapd on $PROV_URI"
88d11b170bStroncd $PROV_DIR
89*e670fd5cSchristos$SLAPD -F slapd.d -h $PROV_URI -d $LVL >> $PROV_LOG 2>&1 &
90d11b170bStronPROV_PID=$!
91d11b170bStronif test $WAIT != 0 ; then
92d11b170bStron	echo PID $PROV_PID
93d11b170bStron	read foo
94d11b170bStronfi
95d11b170bStronKILLPIDS="$KILLPIDS $PROV_PID"
96d11b170bStroncd $TESTWD
97d11b170bStronsleep 1
98d11b170bStronfor i in 1 2 3 4 5; do
99d11b170bStron	$LDAPSEARCH -s base -b "" -H $PROV_URI \
100d11b170bStron		'objectclass=*' > /dev/null 2>&1
101d11b170bStron	RC=$?
102d11b170bStron	test $RC = 0 && break
103d11b170bStron	echo "Waiting $i seconds for slapd to start..."
104d11b170bStron	sleep $i
105d11b170bStrondone
106d11b170bStronif test $RC != 0 ; then
107d11b170bStron	echo "ldapsearch failed ($RC)!"
108d11b170bStron	test $KILLSERVERS != no && kill -HUP $KILLPIDS
109d11b170bStron	exit $RC
110d11b170bStronfi
111d11b170bStron
112d11b170bStronecho "Starting forward1 slapd on $FWD1_URI"
113d11b170bStroncd $FWD1_DIR
114*e670fd5cSchristos$SLAPD -F slapd.d -h $FWD1_URI -d $LVL >> $FWD1_LOG 2>&1 &
115d11b170bStronFWD1_PID=$!
116d11b170bStronif test $WAIT != 0 ; then
117d11b170bStron	echo PID $FWD1_PID
118d11b170bStron	read foo
119d11b170bStronfi
120d11b170bStronKILLPIDS="$KILLPIDS $FWD1_PID"
121d11b170bStroncd $TESTWD
122d11b170bStronsleep 1
123d11b170bStronfor i in 1 2 3 4 5; do
124d11b170bStron	$LDAPSEARCH -s base -b "" -H $FWD1_URI \
125d11b170bStron		'objectclass=*' > /dev/null 2>&1
126d11b170bStron	RC=$?
127d11b170bStron	test $RC = 0 && break
128d11b170bStron	echo "Waiting $i seconds for slapd to start..."
129d11b170bStron	sleep $i
130d11b170bStrondone
131d11b170bStronif test $RC != 0 ; then
132d11b170bStron	echo "ldapsearch failed ($RC)!"
133d11b170bStron	test $KILLSERVERS != no && kill -HUP $KILLPIDS
134d11b170bStron	exit $RC
135d11b170bStronfi
136d11b170bStron
137d11b170bStronecho "Starting consumer slapd on $CONS_URI"
138d11b170bStroncd $CONS_DIR
139*e670fd5cSchristos$SLAPD -F slapd.d -h $CONS_URI -d $LVL >> $CONS_LOG 2>&1 &
140d11b170bStronCONS_PID=$!
141d11b170bStronif test $WAIT != 0 ; then
142d11b170bStron	echo PID $CONS_PID
143d11b170bStron	read foo
144d11b170bStronfi
145d11b170bStronKILLPIDS="$KILLPIDS $CONS_PID"
146d11b170bStroncd $TESTWD
147d11b170bStronsleep 1
148d11b170bStronfor i in 1 2 3 4 5; do
149d11b170bStron	$LDAPSEARCH -s base -b "" -H $CONS_URI \
150d11b170bStron		'objectclass=*' > /dev/null 2>&1
151d11b170bStron	RC=$?
152d11b170bStron	test $RC = 0 && break
153d11b170bStron	echo "Waiting $i seconds for slapd to start..."
154d11b170bStron	sleep $i
155d11b170bStrondone
156d11b170bStronif test $RC != 0 ; then
157d11b170bStron	echo "ldapsearch failed ($RC)!"
158d11b170bStron	test $KILLSERVERS != no && kill -HUP $KILLPIDS
159d11b170bStron	exit $RC
160d11b170bStronfi
161d11b170bStron
162d11b170bStronfor uri in $URIS; do
163d11b170bStron	echo "Adding schema on $uri"
164d11b170bStron	$LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
165d11b170bStroninclude: file://$ABS_SCHEMADIR/core.ldif
166d11b170bStron
167d11b170bStroninclude: file://$ABS_SCHEMADIR/cosine.ldif
168d11b170bStron
169d11b170bStroninclude: file://$ABS_SCHEMADIR/inetorgperson.ldif
170d11b170bStron
171d11b170bStroninclude: file://$ABS_SCHEMADIR/openldap.ldif
172d11b170bStron
173d11b170bStroninclude: file://$ABS_SCHEMADIR/nis.ldif
174d11b170bStron
175d11b170bStronEOF
176d11b170bStron	RC=$?
177d11b170bStron	if test $RC != 0 ; then
178d11b170bStron		echo "ldapadd failed ($RC)!"
179d11b170bStron		test $KILLSERVERS != no && kill -HUP $KILLPIDS
180d11b170bStron		exit $RC
181d11b170bStron	fi
182d11b170bStron
183d11b170bStron	[ "$BACKENDTYPE" = mod ] || continue
184d11b170bStron
185d11b170bStron	echo "Adding backend module on $uri..."
186d11b170bStron	$LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
187d11b170bStrondn: cn=module,cn=config
188d11b170bStronobjectClass: olcModuleList
189d11b170bStroncn: module
190d11b170bStronolcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
191d11b170bStronolcModuleLoad: back_$BACKEND.la
192d11b170bStron
193d11b170bStronEOF
194d11b170bStron	RC=$?
195d11b170bStron	if test $RC != 0 ; then
196d11b170bStron		echo "ldapadd failed for backend module ($RC)!"
197d11b170bStron		test $KILLSERVERS != no && kill -HUP $KILLPIDS
198d11b170bStron		exit $RC
199d11b170bStron	fi
200d11b170bStrondone
201d11b170bStron
202d11b170bStronsyncprov_module=''
203d11b170bStron[ "$AC_syncprov" = syncprovmod ] && syncprov_module="
204d11b170bStrondn: cn=module,cn=config
205d11b170bStronobjectClass: olcModuleList
206d11b170bStroncn: module
207d11b170bStronolcModulePath: $TESTWD/../servers/slapd/overlays
208d11b170bStronolcModuleLoad: syncprov.la"
209d11b170bStron
210d11b170bStronfor uri in $PROV_URI; do
211d11b170bStron	echo "Adding database configuration on $uri"
212d11b170bStron	$LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
213d11b170bStrondn: olcDatabase={1}$BACKEND,cn=config
214d11b170bStronobjectClass: olcDatabaseConfig
215d11b170bStronobjectClass: olc${BACKEND}Config
216d11b170bStronolcDatabase: {1}$BACKEND
217d11b170bStron${nullExclude}olcDbDirectory: ./db
218d11b170bStron$olcDbCheckpoint: 1024 5
219d11b170bStronolcSuffix: $BASEDN
220d11b170bStronolcRootDN: $MANAGERDN
221d11b170bStronolcRootPW: $PASSWD
222d11b170bStron
223d11b170bStron$syncprov_module
224d11b170bStron
225d11b170bStrondn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
226d11b170bStronobjectClass: olcOverlayConfig
227d11b170bStronobjectClass: olcSyncProvConfig
228d11b170bStronolcOverlay: {0}syncprov
229d11b170bStronolcSpCheckpoint: 1 1
230d11b170bStron
231d11b170bStronEOF
232d11b170bStron	RC=$?
233d11b170bStron	if test $RC != 0 ; then
234d11b170bStron		echo "ldapadd failed ($RC)!"
235d11b170bStron		test $KILLSERVERS != no && kill -HUP $KILLPIDS
236d11b170bStron		exit $RC
237d11b170bStron	fi
238d11b170bStron
239d11b170bStron	echo "Populating provider on $uri"
240d11b170bStron	$LDAPADD -D "$MANAGERDN" -H $PROV_URI -w $PASSWD <<EOF >> $TESTOUT 2>&1
241d11b170bStrondn: $BASEDN
242d11b170bStronobjectClass: top
243d11b170bStronobjectClass: organization
244d11b170bStronobjectClass: dcObject
245d11b170bStrondc: example
246d11b170bStrono: Example, Inc
247d11b170bStron
248d11b170bStronEOF
249d11b170bStron	RC=$?
250d11b170bStron	if test $RC != 0 ; then
251d11b170bStron		echo "ldapadd failed ($RC)!"
252d11b170bStron		test $KILLSERVERS != no && kill -HUP $KILLPIDS
253d11b170bStron		exit $RC
254d11b170bStron	fi
255d11b170bStrondone
256d11b170bStron
257d11b170bStronfor uri in $FWD1_URI; do
258d11b170bStron	echo "Adding database configuration on $uri"
259d11b170bStron	$LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
260d11b170bStrondn: olcDatabase={1}$BACKEND,cn=config
261d11b170bStronobjectClass: olcDatabaseConfig
262d11b170bStronobjectClass: olc${BACKEND}Config
263d11b170bStronolcDatabase: {1}$BACKEND
264d11b170bStron${nullExclude}olcDbDirectory: ./db
265d11b170bStron$olcDbCheckpoint: 1024 5
266d11b170bStronolcSuffix: $BASEDN
267d11b170bStronolcRootDN: $MANAGERDN
268d11b170bStronolcRootPW: $PASSWD
269d11b170bStronolcSyncRepl: rid=1 provider=$PROV_URI searchbase="$BASEDN"
270d11b170bStron  binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
271d11b170bStron  type=refreshAndPersist retry="$RETRY" timeout=1
272d11b170bStron
273d11b170bStron$syncprov_module
274d11b170bStron
275d11b170bStrondn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
276d11b170bStronobjectClass: olcOverlayConfig
277d11b170bStronobjectClass: olcSyncProvConfig
278d11b170bStronolcOverlay: {0}syncprov
279d11b170bStronolcSpCheckpoint: 1 1
280d11b170bStron
281d11b170bStronEOF
282d11b170bStron	RC=$?
283d11b170bStron	if test $RC != 0 ; then
284d11b170bStron		echo "ldapadd failed ($RC)!"
285d11b170bStron		test $KILLSERVERS != no && kill -HUP $KILLPIDS
286d11b170bStron		exit $RC
287d11b170bStron	fi
288d11b170bStrondone
289d11b170bStron
290d11b170bStronfor uri in $CONS_URI; do
291d11b170bStron	echo "Adding database configuration on $uri"
292d11b170bStron	$LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
293d11b170bStrondn: olcDatabase={1}$BACKEND,cn=config
294d11b170bStronobjectClass: olcDatabaseConfig
295d11b170bStronobjectClass: olc${BACKEND}Config
296d11b170bStronolcDatabase: {1}$BACKEND
297d11b170bStron${nullExclude}olcDbDirectory: ./db
298d11b170bStron$olcDbCheckpoint: 1024 5
299d11b170bStronolcSuffix: $BASEDN
300d11b170bStronolcRootDN: $MANAGERDN
301d11b170bStronolcRootPW: $PASSWD
302d11b170bStronolcSyncRepl: rid=1 provider=$FWD1_URI searchbase="$BASEDN"
303d11b170bStron  binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
304d11b170bStron  type=refreshAndPersist retry="$RETRY" timeout=1
305d11b170bStron
306d11b170bStronEOF
307d11b170bStron	RC=$?
308d11b170bStron	if test $RC != 0 ; then
309d11b170bStron		echo "ldapadd failed ($RC)!"
310d11b170bStron		test $KILLSERVERS != no && kill -HUP $KILLPIDS
311d11b170bStron		exit $RC
312d11b170bStron	fi
313d11b170bStrondone
314d11b170bStron
315d11b170bStronfor uri in $FWD1_URI $CONS_URI; do
316d11b170bStron	echo "Using ldapsearch to check that $uri received database..."
317d11b170bStron	for i in 1 2 3 4 5; do
318d11b170bStron		$LDAPSEARCH -s base -b "$BASEDN" -H $uri \
319d11b170bStron			'objectclass=*' > /dev/null 2>&1
320d11b170bStron		RC=$?
321d11b170bStron		test $RC = 0 && break
322d11b170bStron		echo "Waiting $i seconds for slapd to receive database..."
323d11b170bStron		sleep $i
324d11b170bStron	done
325d11b170bStron	if test $RC != 0 ; then
326d11b170bStron		echo "ldapsearch failed ($RC)!"
327d11b170bStron		test $KILLSERVERS != no && kill -HUP $KILLPIDS
328d11b170bStron		exit $RC
329d11b170bStron	fi
330d11b170bStrondone
331d11b170bStron
332d11b170bStronRACE_NUM=0
333d11b170bStronERROR=0
334d11b170bStron
335d11b170bStronnEntries=10
336d11b170bStron
337d11b170bStronaddEnd=1
338d11b170bStrondelEnd=1
339d11b170bStron
340d11b170bStronaddIdx=1
341d11b170bStrondelIdx=1
342d11b170bStron
343d11b170bStronwhile test $ERROR -eq 0 -a $RACE_NUM -lt $INITIATION_RACE_TESTS ; do
344d11b170bStron	RACE_NUM=`expr $RACE_NUM + 1`
345d11b170bStron	echo "Running $RACE_NUM of $INITIATION_RACE_TESTS syncrepl initiation race tests..."
346d11b170bStron
347d11b170bStron	echo "Stopping forwarders for add test"
348d11b170bStron	for pid in $FWD1_PID; do
349d11b170bStron		kill -HUP $pid
350d11b170bStron		wait $pid
351d11b170bStron		KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $pid / /"`;
352d11b170bStron	done
353d11b170bStron
354d11b170bStron	addStart=$addEnd
355d11b170bStron	addEnd=`expr $addEnd + $nEntries`
356d11b170bStron
357d11b170bStron	echo "Using ldapadd to add $nEntries entries on provider"
358d11b170bStron	while test $addIdx -lt $addEnd; do
359d11b170bStron		$LDAPADD -D "$MANAGERDN" -H $PROV_URI -w $PASSWD <<EOF >> $TESTOUT 2>&1
360d11b170bStrondn: ou=$addIdx,$BASEDN
361d11b170bStronobjectClass: top
362d11b170bStronobjectClass: organizationalUnit
363d11b170bStronou: $addIdx
364d11b170bStron
365d11b170bStronEOF
366d11b170bStron		RC=$?
367d11b170bStron		if test $RC != 0 ; then
368d11b170bStron			echo "ldapadd failed for entry $addIdx ($RC)!"
369d11b170bStron			test $KILLSERVERS != no && kill -HUP $KILLPIDS
370d11b170bStron			exit $RC
371d11b170bStron		fi
372d11b170bStron		addIdx=`expr $addIdx + 1`
373d11b170bStron	done
374d11b170bStron
375d11b170bStron	echo "Starting forwarders again"
376d11b170bStron	cd $FWD1_DIR
377*e670fd5cSchristos	$SLAPD -F slapd.d -h $FWD1_URI -d $LVL >> $FWD1_LOG 2>&1 &
378d11b170bStron	FWD1_PID=$!
379d11b170bStron	KILLPIDS="$KILLPIDS $FWD1_PID"
380d11b170bStron	cd $TESTWD
381d11b170bStron
382d11b170bStron	addEnd=`expr $addEnd + $nEntries`
383d11b170bStron
384d11b170bStron	echo "Using ldapadd to add $nEntries more entries on provider"
385d11b170bStron	while test $addIdx -lt $addEnd; do
386d11b170bStron		$LDAPADD -D "$MANAGERDN" -H $PROV_URI -w $PASSWD <<EOF >> $TESTOUT 2>&1
387d11b170bStrondn: ou=$addIdx,$BASEDN
388d11b170bStronobjectClass: top
389d11b170bStronobjectClass: organizationalUnit
390d11b170bStronou: $addIdx
391d11b170bStron
392d11b170bStronEOF
393d11b170bStron		RC=$?
394d11b170bStron		if test $RC != 0 ; then
395d11b170bStron			echo "ldapadd failed for entry $addIdx ($RC)!"
396d11b170bStron			test $KILLSERVERS != no && kill -HUP $KILLPIDS
397d11b170bStron			exit $RC
398d11b170bStron		fi
399d11b170bStron		addIdx=`expr $addIdx + 1`
400d11b170bStron	done
401d11b170bStron
402d11b170bStron	for uri in $FWD1_URI $CONS_URI; do
403d11b170bStron		echo "Checking replication to $uri"
404d11b170bStron		RC=32
405d11b170bStron		i=$addStart
406d11b170bStron		while test $i -lt $addEnd; do
407d11b170bStron			for j in 1 2 3 4 5; do
408d11b170bStron				RESULT=`$LDAPSEARCH -H $uri -s base -b "ou=$i,$BASEDN" 2>&1 \
409d11b170bStron					| awk '/^dn:/ {print "OK"}'`
410d11b170bStron				if test "x$RESULT$nullOK" = "xOK" ; then
411d11b170bStron					RC=0
412d11b170bStron					break
413d11b170bStron				fi
414d11b170bStron				echo "Waiting $j seconds for $uri to receive entry $i..."
415d11b170bStron				sleep $j
416d11b170bStron			done
417d11b170bStron			if test $RC != 0 ; then
418d11b170bStron				echo "ERROR: Entry $i not replicated to $uri! ($RC)!"
419d11b170bStron				ERROR=1
420d11b170bStron				break
421d11b170bStron			fi
422d11b170bStron			i=`expr $i + 1`
423d11b170bStron		done
424d11b170bStron		if test $ERROR != 0; then break; fi
425d11b170bStron	done
426d11b170bStron	if test $ERROR != 0; then break; fi
427d11b170bStron
428d11b170bStron	echo "Stopping forwarders for add/delete test"
429d11b170bStron	for pid in $FWD1_PID; do
430d11b170bStron		kill -HUP $pid
431d11b170bStron		wait $pid
432d11b170bStron		KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $pid / /"`;
433d11b170bStron	done
434d11b170bStron
435d11b170bStron	addStart=$addEnd
436d11b170bStron	addEnd=`expr $addEnd + $nEntries`
437d11b170bStron
438d11b170bStron	echo "Using ldapadd to add $nEntries entries on provider"
439d11b170bStron	while test $addIdx -lt $addEnd; do
440d11b170bStron		$LDAPADD -D "$MANAGERDN" -H $PROV_URI -w $PASSWD <<EOF >> $TESTOUT 2>&1
441d11b170bStrondn: ou=$addIdx,$BASEDN
442d11b170bStronobjectClass: top
443d11b170bStronobjectClass: organizationalUnit
444d11b170bStronou: $addIdx
445d11b170bStron
446d11b170bStronEOF
447d11b170bStron		RC=$?
448d11b170bStron		if test $RC != 0 ; then
449d11b170bStron			echo "ldapadd failed for entry $addIdx ($RC)!"
450d11b170bStron			test $KILLSERVERS != no && kill -HUP $KILLPIDS
451d11b170bStron			exit $RC
452d11b170bStron		fi
453d11b170bStron		addIdx=`expr $addIdx + 1`
454d11b170bStron	done
455d11b170bStron
456d11b170bStron	delStart=$delEnd
457d11b170bStron	delEnd=`expr $delEnd + $nEntries`
458d11b170bStron
459d11b170bStron	echo "Using ldapdelete to delete $nEntries entries on provider"
460d11b170bStron	while test $delIdx -lt $delEnd; do
461d11b170bStron		$LDAPDELETE -D "$MANAGERDN" -H $PROV_URI -w $PASSWD "ou=$delIdx,$BASEDN"
462d11b170bStron		RC=$?
463d11b170bStron		if test $RC != 0 ; then
464d11b170bStron			echo "ldapdelete failed ($RC)!"
465d11b170bStron			test $KILLSERVERS != no && kill -HUP $KILLPIDS
466d11b170bStron			exit 1
467d11b170bStron		fi
468d11b170bStron		delIdx=`expr $delIdx + 1`
469d11b170bStron	done
470d11b170bStron
471d11b170bStron	echo "Starting forwarders again"
472d11b170bStron	cd $FWD1_DIR
473*e670fd5cSchristos	$SLAPD -F slapd.d -h $FWD1_URI -d $LVL >> $FWD1_LOG 2>&1 &
474d11b170bStron	FWD1_PID=$!
475d11b170bStron	KILLPIDS="$KILLPIDS $FWD1_PID"
476d11b170bStron	cd $TESTWD
477d11b170bStron
478d11b170bStron	addEnd=`expr $addEnd + $nEntries`
479d11b170bStron	delEnd=`expr $delEnd + $nEntries`
480d11b170bStron
481d11b170bStron	echo "Using ldapadd to add $nEntries more entries on provider"
482d11b170bStron	while test $addIdx -lt $addEnd; do
483d11b170bStron		$LDAPADD -D "$MANAGERDN" -H $PROV_URI -w $PASSWD <<EOF >> $TESTOUT 2>&1
484d11b170bStrondn: ou=$addIdx,$BASEDN
485d11b170bStronobjectClass: top
486d11b170bStronobjectClass: organizationalUnit
487d11b170bStronou: $addIdx
488d11b170bStron
489d11b170bStronEOF
490d11b170bStron		RC=$?
491d11b170bStron		if test $RC != 0 ; then
492d11b170bStron			echo "ldapadd failed for entry $addIdx ($RC)!"
493d11b170bStron			test $KILLSERVERS != no && kill -HUP $KILLPIDS
494d11b170bStron			exit $RC
495d11b170bStron		fi
496d11b170bStron		addIdx=`expr $addIdx + 1`
497d11b170bStron	done
498d11b170bStron
499d11b170bStron	echo "Using ldapdelete to delete $nEntries more entries on provider"
500d11b170bStron	while test $delIdx -lt $delEnd; do
501d11b170bStron		$LDAPDELETE -D "$MANAGERDN" -H $PROV_URI -w $PASSWD "ou=$delIdx,$BASEDN"
502d11b170bStron		RC=$?
503d11b170bStron		if test $RC != 0 ; then
504d11b170bStron			echo "ldapdelete failed ($RC)!"
505d11b170bStron			test $KILLSERVERS != no && kill -HUP $KILLPIDS
506d11b170bStron			exit 1
507d11b170bStron		fi
508d11b170bStron		delIdx=`expr $delIdx + 1`
509d11b170bStron	done
510d11b170bStron
511d11b170bStron	for uri in $FWD1_URI $CONS_URI; do
512d11b170bStron		echo "Checking replication to $uri"
513d11b170bStron		RC=32
514d11b170bStron		i=$addStart
515d11b170bStron		while test $i -lt $addEnd; do
516d11b170bStron			for j in 1 2 3 4 5; do
517d11b170bStron				RESULT=`$LDAPSEARCH -H $uri -s base -b "ou=$i,$BASEDN" 2>&1 \
518d11b170bStron					| awk '/^dn:/ {print "OK"}'`
519d11b170bStron				if test "x$RESULT$nullOK" = "xOK" ; then
520d11b170bStron					RC=0
521d11b170bStron					break
522d11b170bStron				fi
523d11b170bStron				echo "Waiting $j seconds for $uri to receive entry $i..."
524d11b170bStron				sleep $j
525d11b170bStron			done
526d11b170bStron			if test $RC != 0 ; then
527d11b170bStron				echo "ERROR: Entry $i not replicated to $uri! ($RC)!"
528d11b170bStron				ERROR=1
529d11b170bStron				break
530d11b170bStron			fi
531d11b170bStron			i=`expr $i + 1`
532d11b170bStron		done
533d11b170bStron		if test $ERROR != 0; then break; fi
534d11b170bStron
535d11b170bStron		i=$delStart
536d11b170bStron		while test $i -lt $delEnd; do
537d11b170bStron			for j in 1 2 3 4 5; do
538d11b170bStron				$LDAPSEARCH -s base -b "ou=$i,$BASEDN" -H $uri > /dev/null 2>&1
539d11b170bStron				RC=$?
540d11b170bStron				if test $RC = $noObj; then break; fi
541d11b170bStron				echo "Waiting $j seconds for $uri to delete entry $i..."
542d11b170bStron				sleep $j
543d11b170bStron			done
544d11b170bStron			if test $RC != $noObj; then
545d11b170bStron				echo "ERROR: Entry $i not removed on $uri! (RC=$RC)"
546d11b170bStron				ERROR=1
547d11b170bStron				break
548d11b170bStron			fi
549d11b170bStron			i=`expr $i + 1`
550d11b170bStron		done
551d11b170bStron		if test $ERROR != 0; then break; fi
552d11b170bStron	done
553d11b170bStron	if test $ERROR != 0; then break; fi
554d11b170bStron
555d11b170bStron	echo "Stopping forwarders for delete test"
556d11b170bStron	for pid in $FWD1_PID; do
557d11b170bStron		kill -HUP $pid
558d11b170bStron		wait $pid
559d11b170bStron		KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $pid / /"`;
560d11b170bStron	done
561d11b170bStron
562d11b170bStron	delStart=$delEnd
563d11b170bStron	delEnd=`expr $delEnd + $nEntries`
564d11b170bStron
565d11b170bStron	echo "Using ldapdelete to delete entries on provider"
566d11b170bStron	while test $delIdx -lt $delEnd; do
567d11b170bStron		$LDAPDELETE -D "$MANAGERDN" -H $PROV_URI -w $PASSWD "ou=$delIdx,$BASEDN"
568d11b170bStron		RC=$?
569d11b170bStron		if test $RC != 0 ; then
570d11b170bStron			echo "ldapdelete failed ($RC)!"
571d11b170bStron			test $KILLSERVERS != no && kill -HUP $KILLPIDS
572d11b170bStron			exit 1
573d11b170bStron		fi
574d11b170bStron		delIdx=`expr $delIdx + 1`
575d11b170bStron	done
576d11b170bStron
577d11b170bStron	echo "Starting forwarders again"
578d11b170bStron	cd $FWD1_DIR
579*e670fd5cSchristos	$SLAPD -F slapd.d -h $FWD1_URI -d $LVL >> $FWD1_LOG 2>&1 &
580d11b170bStron	FWD1_PID=$!
581d11b170bStron	KILLPIDS="$KILLPIDS $FWD1_PID"
582d11b170bStron	cd $TESTWD
583d11b170bStron
584d11b170bStron	delEnd=`expr $delEnd + $nEntries`
585d11b170bStron
586d11b170bStron	echo "Using ldapdelete to delete $nEntries more entries on provider"
587d11b170bStron	while test $delIdx -lt $delEnd; do
588d11b170bStron		$LDAPDELETE -D "$MANAGERDN" -H $PROV_URI -w $PASSWD "ou=$delIdx,$BASEDN"
589d11b170bStron		RC=$?
590d11b170bStron		if test $RC != 0 ; then
591d11b170bStron			echo "ldapdelete failed ($RC)!"
592d11b170bStron			test $KILLSERVERS != no && kill -HUP $KILLPIDS
593d11b170bStron			exit 1
594d11b170bStron		fi
595d11b170bStron		delIdx=`expr $delIdx + 1`
596d11b170bStron	done
597d11b170bStron
598d11b170bStron	for uri in $FWD1_URI $CONS_URI; do
599d11b170bStron		echo "Checking replication to $uri"
600d11b170bStron		RC=0
601d11b170bStron		i=$delStart
602d11b170bStron		while test $i -lt $delEnd; do
603d11b170bStron			for j in 1 2 3 4 5; do
604d11b170bStron				$LDAPSEARCH -s base -b "ou=$i,$BASEDN" -H $uri > /dev/null 2>&1
605d11b170bStron				RC=$?
606d11b170bStron				if test $RC = $noObj; then break; fi
607d11b170bStron				echo "Waiting $j seconds for $uri to delete entry $i..."
608d11b170bStron				sleep $j
609d11b170bStron			done
610d11b170bStron			if test $RC != $noObj; then
611d11b170bStron				echo "ERROR: Entry $i not removed on $uri! (RC=$RC)"
612d11b170bStron				ERROR=1
613d11b170bStron				break
614d11b170bStron			fi
615d11b170bStron			i=`expr $i + 1`
616d11b170bStron		done
617d11b170bStron		if test $ERROR != 0; then break; fi
618d11b170bStron	done
619d11b170bStron	if test $ERROR != 0; then break; fi
620d11b170bStron
621376af7d7Schristos	sleep 1
622d11b170bStron	echo "Checking contextCSN"
623d11b170bStron	CSN_ERRORS=0
624d11b170bStron	CSN1=`$LDAPSEARCH -H $URI1 -b $BASEDN -s base contextCSN | grep contextCSN`
625d11b170bStron	CSN2=`$LDAPSEARCH -H $URI2 -b $BASEDN -s base contextCSN | grep contextCSN`
626d11b170bStron	CSN3=`$LDAPSEARCH -H $URI3 -b $BASEDN -s base contextCSN | grep contextCSN`
627d11b170bStron
628d11b170bStron	if test -z "$CSN1" ; then
629d11b170bStron		test $BACKEND = null && break
630d11b170bStron		echo "ERROR: contextCSN empty on provider"
631d11b170bStron		ERROR=1
632d11b170bStron		break
633d11b170bStron	fi
634d11b170bStron	nCSN=`echo "$CSN1" | wc -l`
635d11b170bStron	if test "$nCSN" -ne 1 ; then
636*e670fd5cSchristos		echo "ERROR: Wrong contextCSN count on provider, should be 1"
637d11b170bStron		echo "$CSN1"
638d11b170bStron		test $KILLSERVERS != no && kill -HUP $KILLPIDS
639d11b170bStron		exit 1
640d11b170bStron	fi
641d11b170bStron	if  test -z "$CSN2" -o "$CSN1" != "$CSN2" ; then
642d11b170bStron		echo "ERROR: contextCSN mismatch between provider and consumer"
643d11b170bStron		echo "contextCSN on provider: $CSN1"
644d11b170bStron		echo "contextCSN on consumer: $CSN2"
645d11b170bStron		ERROR=1
646d11b170bStron		break
647d11b170bStron	fi
648d11b170bStron	if  test -z "$CSN3" -o "$CSN1" != "$CSN3" ; then
649d11b170bStron		echo "ERROR: contextCSN mismatch between provider and forward1"
650d11b170bStron		echo "contextCSN on provider: $CSN1"
651d11b170bStron		echo "contextCSN on forward1: $CSN3"
652d11b170bStron		ERROR=1
653d11b170bStron		break
654d11b170bStron	fi
655d11b170bStrondone
656d11b170bStron
657d11b170bStrontest $KILLSERVERS != no && kill -HUP $KILLPIDS
658d11b170bStron
659d11b170bStronif test $ERROR != 0; then
660d11b170bStron	echo "Error found after $RACE_NUM of $INITIATION_RACE_TESTS iterations"
661d11b170bStron	exit 1
662d11b170bStronelse
663d11b170bStron	echo "No race errors found after $INITIATION_RACE_TESTS iterations"
664d11b170bStronfi
665d11b170bStron
666d11b170bStronecho ">>>>> Test succeeded"
667d11b170bStron
668d11b170bStronexit 0
669