Regression test, test_http.sh, moved to sub directory test. The test
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 15 May 2007 15:50:47 +0000 (15:50 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 15 May 2007 15:50:47 +0000 (15:50 +0000)
makes a session, tries stat, search and show on a local yaz-ztest.
Route make_sessionid modified to return deterministic session ID.
If that is considered a problem an option or configuration must be
added to Pazpar2 so this can be tuned.

18 files changed:
Makefile.am
configure.ac
src/Makefile.am
src/http_command.c
src/test_http.cfg [deleted file]
src/test_http.sh [deleted file]
src/test_http.xml [deleted file]
test/.cvsignore [new file with mode: 0644]
test/Makefile.am [new file with mode: 0644]
test/test_http.cfg [new file with mode: 0644]
test/test_http.sh [new file with mode: 0755]
test/test_http.xml [new file with mode: 0644]
test/test_http_1.res [new file with mode: 0644]
test/test_http_2.res [new file with mode: 0644]
test/test_http_3.res [new file with mode: 0644]
test/test_http_4.res [new file with mode: 0644]
test/test_http_5.res [new file with mode: 0644]
test/test_http_urls [new file with mode: 0644]

index b183ff1..14c1e6c 100644 (file)
@@ -1,9 +1,9 @@
-# $Id: Makefile.am,v 1.7 2007-04-10 08:48:55 adam Exp $
+# $Id: Makefile.am,v 1.8 2007-05-15 15:50:47 adam Exp $
 
 AUTOMAKE_OPTIONS = foreign
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = src doc
+SUBDIRS = src test doc
 
 EXTRA_DIST = README NEWS LICENSE buildconf.sh Doxyfile.in m4/yaz.m4 
 
index 2ba5b4a..57554c5 100644 (file)
@@ -31,6 +31,7 @@ AC_CONFIG_FILES([
        Doxyfile
        Makefile
        src/Makefile
+       test/Makefile
        doc/Makefile
        doc/local.ent
        doc/common/Makefile
index 21f2e53..26867af 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.21 2007-05-15 08:56:03 adam Exp $
+# $Id: Makefile.am,v 1.22 2007-05-15 15:50:48 adam Exp $
 
 bin_PROGRAMS = pazpar2
 check_PROGRAMS = test_config \
@@ -8,11 +8,7 @@ check_PROGRAMS = test_config \
       test_relevance \
       test_sel_thread
 
-check_SCRIPTS = test_http.sh
-
-EXTRA_DIST = test_http.xml test_http.cfg $(check_SCRIPTS)
-
-TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
+TESTS = $(check_PROGRAMS)
 
 noinst_LIBRARIES = libpazpar2.a
 
index 35bed6b..879159d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: http_command.c,v 1.41 2007-04-23 21:05:23 adam Exp $
+/* $Id: http_command.c,v 1.42 2007-05-15 15:50:48 adam Exp $
    Copyright (c) 2006-2007, Index Data.
 
 This file is part of Pazpar2.
@@ -20,7 +20,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  */
 
 /*
- * $Id: http_command.c,v 1.41 2007-04-23 21:05:23 adam Exp $
+ * $Id: http_command.c,v 1.42 2007-05-15 15:50:48 adam Exp $
  */
 
 #include <stdio.h>
@@ -119,9 +119,12 @@ static void error(struct http_response *rs, char *code, char *msg, char *txt)
 
 unsigned int make_sessionid()
 {
+    static int seq = 0;
+#if 1
+    return ++seq;
+#else
     struct timeval t;
     unsigned int res;
-    static int seq = 0;
 
     seq++;
     if (gettimeofday(&t, 0) < 0)
@@ -129,6 +132,7 @@ unsigned int make_sessionid()
     res = t.tv_sec;
     res = ((res << 8) | (seq & 0xff)) & ((1U << 31) - 1);
     return res;
+#endif
 }
 
 static struct http_session *locate_session(struct http_request *rq, struct http_response *rs)
diff --git a/src/test_http.cfg b/src/test_http.cfg
deleted file mode 100644 (file)
index ec07815..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<pazpar2 xmlns="http://www.indexdata.com/pazpar2/1.0">
-<!-- $Id: test_http.cfg,v 1.1 2007-05-15 08:56:03 adam Exp $ -->
-<!-- Used by test_http.sh -->
-<server>
-  <listen port="9763"/>
-  <proxy host="localhost"/>
-  <settings src="../etc/settings"/>
-
-  <service>
-    <metadata name="url" merge="unique"/>
-    <metadata name="title" brief="yes" sortkey="skiparticle" merge="longest" rank="6"/>
-    <metadata name="isbn"/>
-    <metadata name="date" brief="yes" sortkey="numeric" type="year" merge="range"
-           termlist="yes"/>
-    <metadata name="author" brief="yes" termlist="yes" merge="longest" rank="2"/>
-    <metadata name="subject" merge="unique" termlist="yes" rank="3"/>
-    <metadata name="id"/>
-    <metadata name="lccn" merge="unique"/>
-    <metadata name="description" merge="longest" rank="3"/>
-  </service>
-</server>
-
-<targetprofiles type="local" src="../zeerex/records/"/>
-
-</pazpar2>
diff --git a/src/test_http.sh b/src/test_http.sh
deleted file mode 100755 (executable)
index ed76cc6..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-# $Id: test_http.sh,v 1.1 2007-05-15 08:56:03 adam Exp $
-srcdir=${srcdir:-"."}
-./pazpar2 -f ${srcdir}/test_http.cfg -t ${srcdir}/test_http.xml >test_http.log 2>&1 &
-PP2PID=$!
-sleep 1
-if ps -p $PP2PID >/dev/null 2>&1; then
-    :
-    # echo "Started OK PID=$PP2PID"
-else
-    echo "pazpar2 failed to start"
-    exit 1
-fi
-
-kill $PP2PID
-exit 0
-
-# Local Variables:
-# mode:shell-script
-# sh-indentation: 2
-# sh-basic-offset: 4
-# End:
diff --git a/src/test_http.xml b/src/test_http.xml
deleted file mode 100644 (file)
index 5f5a905..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<settings target="localhost:9999/Default">
-
-  <!-- Used by test test_http.sh -->
-  <!-- $Id: test_http.xml,v 1.1 2007-05-15 08:56:03 adam Exp $ -->
-
-  <set name="pz:name" value="Local Test"/>
-
-  <!-- mapping for unqualified search -->
-  <set name="pz:cclmap:term" value="u=1016 t=l,r s=al"/>
-
-  <!-- field-specific mappings -->
-  <set name="pz:cclmap:ti" value="u=4 s=al"/>
-  <set name="pz:cclmap:su" value="u=21 s=al"/>
-  <set name="pz:cclmap:isbn" value="u=7"/>
-  <set name="pz:cclmap:issn" value="u=8"/>
-  <set name="pz:cclmap:date" value="u=30 r=r"/>
-
-  <!-- Retrieval settings -->
-
-  <set name="pz:requestsyntax" value="marc21"/>
-  <!-- <set name="pz:elements" value="F"/> NOT YET IMPLEMENTED -->
-
-  <!-- Result normalization settings -->
-
-  <set name="pz:nativesyntax" value="iso2709"/>
-  <set name="pz:xslt" value="../etc/marc21.xsl"/>
-
-</settings>
diff --git a/test/.cvsignore b/test/.cvsignore
new file mode 100644 (file)
index 0000000..cb6a995
--- /dev/null
@@ -0,0 +1,4 @@
+*.log
+*.dif
+Makefile
+Makefile.in
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644 (file)
index 0000000..abf372a
--- /dev/null
@@ -0,0 +1,15 @@
+# $Id: Makefile.am,v 1.1 2007-05-15 15:50:48 adam Exp $
+
+check_SCRIPTS = test_http.sh
+
+EXTRA_DIST = test_http.xml test_http.cfg test_http_urls $(check_SCRIPTS)
+
+TESTS = $(check_SCRIPTS)
+
+MAINTAINERCLEANFILES = Makefile.in
+
+CONFIG_CLEAN_FILES=*.log
+
+dist-hook:
+       cp test_http_*.res $(distdir)
+
diff --git a/test/test_http.cfg b/test/test_http.cfg
new file mode 100644 (file)
index 0000000..483eb70
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<pazpar2 xmlns="http://www.indexdata.com/pazpar2/1.0">
+<!-- $Id: test_http.cfg,v 1.1 2007-05-15 15:50:48 adam Exp $ -->
+<!-- Used by test_http.sh -->
+<server>
+  <listen port="9763"/>
+  <proxy host="localhost"/>
+  <settings src="../etc/settings"/>
+
+  <service>
+    <metadata name="url" merge="unique"/>
+    <metadata name="title" brief="yes" sortkey="skiparticle" merge="longest" rank="6"/>
+    <metadata name="isbn"/>
+    <metadata name="date" brief="yes" sortkey="numeric" type="year" merge="range"
+           termlist="yes"/>
+    <metadata name="author" brief="yes" termlist="yes" merge="longest" rank="2"/>
+    <metadata name="subject" merge="unique" termlist="yes" rank="3"/>
+    <metadata name="id"/>
+    <metadata name="lccn" merge="unique"/>
+    <metadata name="description" merge="longest" rank="3"/>
+  </service>
+</server>
+
+<targetprofiles type="local" src="../zeerex/records/"/>
+
+</pazpar2>
diff --git a/test/test_http.sh b/test/test_http.sh
new file mode 100755 (executable)
index 0000000..b99971f
--- /dev/null
@@ -0,0 +1,96 @@
+#!/bin/sh
+# $Id: test_http.sh,v 1.1 2007-05-15 15:50:48 adam Exp $
+#
+# Regression test using pazpar2 against yaz-ztest
+# Reads Pazpar2 URLs from test_http_urls
+#            Outputs to test_http_<no>.log
+#            Matches against results in test_htttp_<no>.res
+#
+
+
+# srcdir might be set by make
+srcdir=${srcdir:-"."}
+
+# Find a suitable yaz-ztest
+yt=""
+for d in /usr/bin /usr/local/bin ../../yaz/ztest; do
+    yt=${d}/yaz-ztest
+    if test -x ${yt}; then
+       break
+    fi
+done
+if test -z "${yt}"; then
+    echo "No yaz-ztest found. Skipping"
+    exit 0
+fi
+
+# Fire up yaz-ztest (should match port in test_http.xml)
+$yt -l test_http_ztest.log tcp:@:9764 &
+YTPID=$!
+
+# Fire yp pazpar2
+../src/pazpar2 -f ${srcdir}/test_http.cfg -t ${srcdir}/test_http.xml >test_http_pp2.log 2>&1 &
+PP2PID=$!
+
+# Give both programs room to start properly..
+sleep 1
+
+# Set to success by default.. Will be set to non-zero in case of failure
+code=0
+
+if ps -p $PP2PID >/dev/null 2>&1; then
+    :
+else
+    code=1
+    PP2PID=""
+    echo "pazpar2 failed to start"
+fi
+
+if ps -p $YTPID >/dev/null 2>&1; then
+    :
+else
+    code=1
+    YTPID=""
+    echo "yaz-ztest failed to start"
+fi
+# We can start test for real
+
+testno=1
+for f in `cat ${srcdir}/test_http_urls`; do
+    OUT1=${srcdir}/test_http_${testno}.res
+    OUT2=${srcdir}/test_http_${testno}.log
+    DIFF=${srcdir}/test_http_${testno}.dif
+    if test -f $OUT1; then
+       rm -f $OUT2
+       wget -q -O $OUT2 $f
+       if diff $OUT1 $OUT2 >$DIFF; then
+           echo "Test $testno: OK"
+       else
+           echo "Test $testno: Failed. See $OUT1, $OUT2 and $DIFF"
+           code=1
+       fi
+    else
+       echo "Test $testno: Making for the first time"
+       wget -q -O $OUT1 $f
+       code=1
+    fi
+    testno=`expr $testno + 1`
+done
+
+sleep 1
+# Kill programs
+if test -n "$YTPID"; then
+    kill $YTPID
+fi
+
+if test -n "$PP2PID"; then
+    kill $PP2PID
+fi
+
+exit $code
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation: 2
+# sh-basic-offset: 4
+# End:
diff --git a/test/test_http.xml b/test/test_http.xml
new file mode 100644 (file)
index 0000000..a0f1089
--- /dev/null
@@ -0,0 +1,28 @@
+<settings target="localhost:9764/Default">
+
+  <!-- Used by test test_http.sh -->
+  <!-- $Id: test_http.xml,v 1.1 2007-05-15 15:50:48 adam Exp $ -->
+
+  <set name="pz:name" value="Local Test"/>
+
+  <!-- mapping for unqualified search -->
+  <set name="pz:cclmap:term" value="u=1016 t=l,r s=al"/>
+
+  <!-- field-specific mappings -->
+  <set name="pz:cclmap:ti" value="u=4 s=al"/>
+  <set name="pz:cclmap:su" value="u=21 s=al"/>
+  <set name="pz:cclmap:isbn" value="u=7"/>
+  <set name="pz:cclmap:issn" value="u=8"/>
+  <set name="pz:cclmap:date" value="u=30 r=r"/>
+
+  <!-- Retrieval settings -->
+
+  <set name="pz:requestsyntax" value="marc21"/>
+  <!-- <set name="pz:elements" value="F"/> NOT YET IMPLEMENTED -->
+
+  <!-- Result normalization settings -->
+
+  <set name="pz:nativesyntax" value="iso2709"/>
+  <set name="pz:xslt" value="../etc/marc21.xsl"/>
+
+</settings>
diff --git a/test/test_http_1.res b/test/test_http_1.res
new file mode 100644 (file)
index 0000000..ae5db74
--- /dev/null
@@ -0,0 +1 @@
+<init><status>OK</status><session>1</session><protocol>1</protocol></init>
\ No newline at end of file
diff --git a/test/test_http_2.res b/test/test_http_2.res
new file mode 100644 (file)
index 0000000..48f18ee
--- /dev/null
@@ -0,0 +1,13 @@
+<stat><activeclients>0</activeclients>
+<hits>0</hits>
+<records>0</records>
+<clients>0</clients>
+<unconnected>0</unconnected>
+<connecting>0</connecting>
+<initializing>0</initializing>
+<searching>0</searching>
+<presenting>0</presenting>
+<idle>0</idle>
+<failed>0</failed>
+<error>0</error>
+</stat>
\ No newline at end of file
diff --git a/test/test_http_3.res b/test/test_http_3.res
new file mode 100644 (file)
index 0000000..792c56c
--- /dev/null
@@ -0,0 +1 @@
+<ping><status>OK</status></ping>
\ No newline at end of file
diff --git a/test/test_http_4.res b/test/test_http_4.res
new file mode 100644 (file)
index 0000000..d2e0e58
--- /dev/null
@@ -0,0 +1 @@
+<search><status>OK</status></search>
\ No newline at end of file
diff --git a/test/test_http_5.res b/test/test_http_5.res
new file mode 100644 (file)
index 0000000..e9f1ea8
--- /dev/null
@@ -0,0 +1,51 @@
+<show>
+<status>OK</status>
+<activeclients>0</activeclients>
+<merged>6</merged>
+<total>7</total>
+<start>0</start>
+<num>6</num>
+<hit>
+
+<md-title>How to program a computer</md-title>
+<md-author>Jack Collins</md-author><location id="localhost:9764/Default" name="Local Test"></location>
+<location id="localhost:9764/Default" name="Local Test"></location>
+<count>2</count>
+<recid>0</recid>
+</hit>
+<hit>
+
+<md-title>The Computer Bible</md-title>
+<md-date>1973-1980</md-date>
+<md-author>Freedman, David Noel</md-author><location id="localhost:9764/Default" name="Local Test"></location>
+<recid>2</recid>
+</hit>
+<hit>
+
+<md-title>The Puget Sound Region : a portfolio of thematic computer maps</md-title>
+<md-date>1974</md-date>
+<md-author>Hoerauf, Eugene A</md-author><location id="localhost:9764/Default" name="Local Test"></location>
+<recid>3</recid>
+</hit>
+<hit>
+
+<md-title>Computer processing of dynamic images from an Anger scintillation camera : the proceedings of a workshop</md-title>
+<md-date>1974</md-date>
+<md-author>Larson, Kenneth B</md-author><location id="localhost:9764/Default" name="Local Test"></location>
+<recid>1</recid>
+</hit>
+<hit>
+
+<md-title>Computer science &amp; technology : proceedings of a workshop held at the National Bureau of Standards, Gaithersburg, MD, June 3-4, 1976</md-title>
+<md-date>1977</md-date>
+<md-author>Evans, John Martin</md-author><location id="localhost:9764/Default" name="Local Test"></location>
+<recid>5</recid>
+</hit>
+<hit>
+
+<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine : proceedings of the workshop</md-title>
+<md-date>1977</md-date>
+<md-author>Ter-Pogossian, Michel M</md-author><location id="localhost:9764/Default" name="Local Test"></location>
+<recid>4</recid>
+</hit>
+</show>
diff --git a/test/test_http_urls b/test/test_http_urls
new file mode 100644 (file)
index 0000000..90eceae
--- /dev/null
@@ -0,0 +1,5 @@
+http://localhost:9763/search.pz2?command=init
+http://localhost:9763/search.pz2?session=1&command=stat
+http://localhost:9763/search.pz2?session=1&command=ping
+http://localhost:9763/search.pz2?session=1&command=search&query=computer
+http://localhost:9763/search.pz2?session=1&command=show&start=0&number=1