test039-glue-ldap-concurrency revision 1.1.1.9
1#! /bin/sh
2# $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2021 The OpenLDAP Foundation.
6## All rights reserved.
7##
8## Redistribution and use in source and binary forms, with or without
9## modification, are permitted only as authorized by the OpenLDAP
10## Public License.
11##
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>.
15
16echo "running defines.sh"
17. $SRCDIR/scripts/defines.sh
18
19echo ""
20
21if test $BACKLDAP = ldapno ; then 
22	echo "ldap backend not available, test skipped"
23	exit 0
24fi
25
26if test $RWM = rwmno ; then 
27	echo "rwm (rewrite/remap) overlay not available, test skipped"
28	exit 0
29fi 
30
31if test x$TESTLOOPS = x ; then
32	TESTLOOPS=50
33fi
34
35if test x$TESTOLOOPS = x ; then
36	TESTOLOOPS=1
37fi
38
39if test x$TESTCHILDREN = x ; then
40	TESTCHILDREN=20
41fi
42
43rm -rf $TESTDIR
44
45mkdir -p $TESTDIR $DBDIR1 $DBDIR2
46
47echo "Starting slapd on TCP/IP port $PORT1..."
48. $CONFFILTER $BACKEND < $METACONF1 > $CONF1
49$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
50PID=$!
51if test $WAIT != 0 ; then
52    echo PID $PID
53    read foo
54fi
55KILLPIDS="$PID"
56
57sleep 1
58
59echo "Using ldapsearch to check that slapd is running..."
60for i in 0 1 2 3 4 5; do
61	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
62		'objectclass=*' > /dev/null 2>&1
63	RC=$?
64	if test $RC = 0 ; then
65		break
66	fi
67	echo "Waiting 5 seconds for slapd to start..."
68	sleep 5
69done
70if test $RC != 0 ; then
71	echo "ldapsearch failed ($RC)!"
72	test $KILLSERVERS != no && kill -HUP $KILLPIDS
73	exit $RC
74fi
75
76echo "Using ldapadd to populate the database..."
77$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD < \
78	$LDIFORDERED > $TESTOUT 2>&1
79RC=$?
80if test $RC != 0 ; then
81	echo "ldapadd failed ($RC)!"
82	test $KILLSERVERS != no && kill -HUP $KILLPIDS
83	exit $RC
84fi
85
86echo "Starting slapd on TCP/IP port $PORT2..."
87. $CONFFILTER $BACKEND < $METACONF2 > $CONF2
88$SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
89PID=$!
90if test $WAIT != 0 ; then
91    echo PID $PID
92    read foo
93fi
94KILLPIDS="$KILLPIDS $PID"
95
96sleep 1
97
98echo "Using ldapsearch to check that slapd is running..."
99for i in 0 1 2 3 4 5; do
100	$LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
101		'objectclass=*' > /dev/null 2>&1
102	RC=$?
103	if test $RC = 0 ; then
104		break
105	fi
106	echo "Waiting 5 seconds for slapd to start..."
107	sleep 5
108done
109if test $RC != 0 ; then
110	echo "ldapsearch failed ($RC)!"
111	test $KILLSERVERS != no && kill -HUP $KILLPIDS
112	exit $RC
113fi
114
115echo "Using ldapadd to populate the database..."
116$LDAPADD -D "$METAMANAGERDN" -H $URI2 -w $PASSWD < \
117	$LDIFMETA >> $TESTOUT 2>&1
118RC=$?
119if test $RC != 0 ; then
120	echo "ldapadd failed ($RC)!"
121	test $KILLSERVERS != no && kill -HUP $KILLPIDS
122	exit $RC
123fi
124
125echo "Starting slapd on TCP/IP port $PORT3..."
126. $CONFFILTER $BACKEND < $GLUELDAPCONF > $CONF3
127$SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 &
128PID=$!
129if test $WAIT != 0 ; then
130    echo PID $PID
131    read foo
132fi
133KILLPIDS="$KILLPIDS $PID"
134
135sleep 1
136
137echo "Using ldapsearch to check that slapd is running..."
138for i in 0 1 2 3 4 5; do
139	$LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \
140		'objectclass=*' > /dev/null 2>&1
141	RC=$?
142	if test $RC = 0 ; then
143		break
144	fi
145	echo "Waiting 5 seconds for slapd to start..."
146	sleep 5
147done
148if test $RC != 0 ; then
149	echo "ldapsearch failed ($RC)!"
150	test $KILLSERVERS != no && kill -HUP $KILLPIDS
151	exit $RC
152fi
153
154cat /dev/null > $SEARCHOUT
155
156mkdir -p $TESTDIR/$DATADIR
157METABASEDN="o=Example,c=US"
158for f in $DATADIR/do_* ; do
159	sed -e "s;$BASEDN;$METABASEDN;" $f > $TESTDIR/$f
160done
161
162# add a read that matches only the local database, but selects 
163# also the remote as candidate; this should be removed to compare
164# execution times with test008...
165for f in $TESTDIR/$DATADIR/do_read.* ; do
166	echo "ou=Meta,$METABASEDN" >> $f
167done
168
169# add a read that matches a referral in the local database only, 
170# but selects also the remote as candidate; this should be removed 
171# to compare execution times with test008...
172for f in $TESTDIR/$DATADIR/do_read.* ; do
173	echo "cn=Somewhere,ou=Meta,$METABASEDN" >> $f
174done
175
176# add a bind that resolves to a referral
177for f in $TESTDIR/$DATADIR/do_bind.* ; do
178	echo "cn=Foo,ou=Meta,$METABASEDN" >> $f
179	echo "bar" >> $f
180	echo "" >> $f
181	echo "" >> $f
182done
183
184# fix test data to include back-monitor, if available
185# NOTE: copies do_* files from $TESTDIR/$DATADIR to $TESTDIR
186$MONITORDATA "$TESTDIR/$DATADIR" "$TESTDIR"
187
188echo "Using tester for concurrent server access..."
189BINDDN="cn=Manager,o=Local"
190PASSWD="secret"
191$SLAPDTESTER -P "$PROGDIR" -d "$TESTDIR" -H $URI3 \
192	-D "$BINDDN" -w $PASSWD \
193	-l $TESTLOOPS -L $TESTOLOOPS -j $TESTCHILDREN -r 20 \
194	-i '!REFERRAL' -i '*INVALID_CREDENTIALS' -SS
195RC=$?
196
197if test $RC != 0 ; then
198	echo "slapd-tester failed ($RC)!"
199	test $KILLSERVERS != no && kill -HUP $KILLPIDS
200	exit $RC
201fi 
202
203echo "Using ldapsearch to retrieve all the entries..."
204$LDAPSEARCH -S "" -b "$METABASEDN" -H $URI3 \
205			'(objectClass=*)' > $SEARCHOUT 2>&1
206RC=$?
207
208test $KILLSERVERS != no && kill -HUP $KILLPIDS
209
210if test $RC != 0 ; then
211	echo "ldapsearch failed ($RC)!"
212	exit $RC
213fi
214
215echo "Filtering ldapsearch results..."
216$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
217echo "Filtering original ldif used to create database..."
218$LDIFFILTER < $METACONCURRENCYOUT > $LDIFFLT
219echo "Comparing filter output..."
220$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
221
222if test $? != 0 ; then
223	echo "comparison failed - slapd-ldap search/modification didn't succeed"
224	exit 1
225fi
226
227echo ">>>>> Test succeeded"
228
229test $KILLSERVERS != no && wait
230
231exit 0
232