open-source-search-engine/qa.cpp

2109 lines
49 KiB
C++
Raw Normal View History

2014-04-05 22:33:42 +04:00
#include <string.h>
#include "SafeBuf.h"
#include "HttpServer.h"
2014-07-26 17:59:05 +04:00
TcpSocket *g_qaSock = NULL;
SafeBuf g_qaOutput;
bool g_qaInProgress = false;
2014-07-28 22:13:02 +04:00
long g_numErrors;
2014-07-26 17:59:05 +04:00
2014-07-29 06:15:31 +04:00
static long s_checkCRC = 0;
2014-07-28 22:13:02 +04:00
static bool s_registered = false;
2014-07-11 03:42:22 +04:00
bool qatest ( ) ;
2014-07-28 22:13:02 +04:00
void qatestWrapper ( int fd , void *state ) {
qatest();
}
// wait X seconds, call sleep timer... then call qatest()
void wait( float seconds ) {
// put into milliseconds
2014-09-19 01:41:33 +04:00
long delay = (long)(seconds * 1000.0);
2014-07-28 22:13:02 +04:00
if ( g_loop.registerSleepCallback ( delay ,
NULL , // state
qatestWrapper,//m_masterLoop
0 )) {// niceness
s_registered = true;
// wait for it, return -1 since we blocked
return;
}
log("qa: could not register callback!");
return;
}
// first inject a set list of urls
static char **s_urlPtrs = NULL;
static char **s_contentPtrs = NULL;
static SafeBuf s_ubuf1;
static SafeBuf s_ubuf2;
static SafeBuf s_cbuf2;
2014-04-05 22:33:42 +04:00
2014-07-26 19:12:42 +04:00
static Url s_url;
2014-07-12 06:07:49 +04:00
void markOut ( char *content , char *needle ) {
2014-07-07 03:47:04 +04:00
2014-07-12 06:07:49 +04:00
if ( ! content ) return;
2014-07-07 09:06:33 +04:00
loop:
2014-07-12 06:07:49 +04:00
char *s = strstr ( content , needle );
2014-07-07 03:47:04 +04:00
if ( ! s ) return;
// advance over name like "rand64=" to avoid hitting those digits
s += gbstrlen(needle);
2014-07-07 03:47:04 +04:00
for ( ; *s && ! is_digit(*s); s++ );
2014-07-07 06:43:00 +04:00
// find end of digit stream
//char *end = s;
//while ( ; *end && is_digit(*s); end++ );
// just bury the digit stream now, zeroing out was not
// a consistent LENGTH if we had 10 hits vs 9... making the hash
// different
// space out digits
for ( ; *s && is_digit(*s); s++ ) *s = ' ';
// loop for more for the "rand64=" thing
content = s;
goto loop;
2014-07-07 06:43:00 +04:00
}
// do not hash
2014-07-07 09:06:33 +04:00
long qa_hash32 ( char *s ) {
2014-07-07 06:43:00 +04:00
unsigned long h = 0;
long k = 0;
for ( long i = 0 ; s[i] ; i++ ) {
// skip if not first space and back to back spaces
if ( s[i] == ' ' &&i>0 && s[i-1]==' ') continue;
h ^= g_hashtab [(unsigned char)k] [(unsigned char)s[i]];
k++;
}
return h;
2014-07-07 03:47:04 +04:00
}
#define MAXFLAGS 50
2014-07-27 07:05:05 +04:00
class QATest {
public:
bool (* m_func)();
char *m_testName;
char *m_testDesc;
char m_doTest;
// we set s_flags to this
long m_flags[MAXFLAGS];
2014-07-27 07:05:05 +04:00
};
2014-07-12 06:07:49 +04:00
static char *s_content = NULL;
2014-07-27 05:43:11 +04:00
static HashTableX s_ht;
2014-07-27 07:05:05 +04:00
static QATest *s_qt = NULL;
2014-07-07 01:13:00 +04:00
2014-07-29 06:15:31 +04:00
bool saveHashTable ( ) {
if ( s_ht.m_numSlotsUsed <= 0 ) return true;
SafeBuf fn;
fn.safePrintf("%s/qa/",g_hostdb.m_dir);
log("qa: saving crctable.dat");
s_ht.save ( fn.getBufStart() , "crctable.dat" );
return true;
}
void makeQADir ( ) {
static bool s_init = false;
if ( s_init ) return;
s_init = true;
s_ht.set(4,4,1024,NULL,0,false,0,"qaht");
// make symlink
//char cmd[512];
//snprintf(cmd,"cd %s/html ;ln -s ../qa ./qa", g_hostdb.m_dir);
//system(cmd);
char dir[1024];
snprintf(dir,1000,"%sqa",g_hostdb.m_dir);
log("mkdir mkdir %s",dir);
long status = ::mkdir ( dir ,
S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IWGRP | S_IXGRP |
S_IROTH | S_IXOTH );
if ( status == -1 && errno != EEXIST && errno )
log("qa: Failed to make directory %s: %s.",
dir,mstrerror(errno));
// try to load from disk
SafeBuf fn;
fn.safePrintf("%s/qa/",g_hostdb.m_dir);
log("qa: loading crctable.dat");
s_ht.load ( fn.getBufStart() , "crctable.dat" );
}
2014-07-11 20:45:34 +04:00
void processReply ( char *reply , long replyLen ) {
// store our current reply
SafeBuf fb2;
2014-07-11 20:45:34 +04:00
fb2.safeMemcpy(reply,replyLen );
fb2.nullTerm();
// log that we got the reply
2014-07-11 20:45:34 +04:00
log("qa: got reply(len=%li)(errno=%s)=%s",
replyLen,mstrerror(g_errno),reply);
2014-07-07 09:06:33 +04:00
2014-07-12 06:07:49 +04:00
char *content = NULL;
2014-07-11 20:45:34 +04:00
long contentLen = 0;
2014-07-07 03:47:04 +04:00
2014-07-11 20:45:34 +04:00
// get mime
if ( reply ) {
HttpMime mime;
mime.set ( reply, replyLen , NULL );
// only hash content since mime has a timestamp in it
content = mime.getContent();
contentLen = mime.getContentLen();
2014-07-12 06:07:49 +04:00
if ( content && contentLen>0 && content[contentLen] ) {
char *xx=NULL;*xx=0; }
2014-07-11 20:45:34 +04:00
}
2014-07-07 03:47:04 +04:00
2014-07-12 06:07:49 +04:00
if ( ! content ) {
content = "";
contentLen = 0;
}
s_content = content;
2014-07-11 03:42:22 +04:00
2014-07-07 03:47:04 +04:00
// take out <responseTimeMS>
2014-07-12 06:07:49 +04:00
markOut ( content , "<currentTimeUTC>");
markOut ( content , "<responseTimeMS>");
2014-07-07 03:47:04 +04:00
2014-07-07 05:53:05 +04:00
// until i figure this one out, take it out
2014-07-12 06:07:49 +04:00
markOut ( content , "<docsInCollection>");
2014-07-07 05:53:05 +04:00
2014-07-07 09:06:33 +04:00
// until i figure this one out, take it out
2014-07-12 06:07:49 +04:00
markOut ( content , "<hits>");
2014-07-07 09:06:33 +04:00
// for those links in the html pages
markOut ( content, "rand64=");
2014-07-14 23:44:32 +04:00
// for json
markOut ( content , "\"currentTimeUTC\":" );
markOut ( content , "\"responseTimeMS\":");
markOut ( content , "\"docsInCollection\":");
// for xml
markOut ( content , "<currentTimeUTC>" );
markOut ( content , "<responseTimeMS>");
markOut ( content , "<docsInCollection>");
markOut ( content , "<firstIndexedDateUTC>");
2014-07-14 23:44:32 +04:00
2014-08-02 20:07:33 +04:00
// indexed 1 day ago
markOut ( content,"indexed:");
// modified 1 day ago
markOut ( content,"modified:");
2014-08-07 03:00:25 +04:00
// s_gigabitCount... it is perpetually incrementing static counter
// in PageResults.cpp
markOut(content,"ccc(");
markOut(content,"id=fd");
markOut(content,"id=sd");
// for some reason the term freq seems to change a little in
// the scoring table
markOut(content,"id=tf");
// # of collections in the admin page: ..."4 Collections"
markOut(content,"px;color:black;\"><center><nobr><b>");
2014-07-07 06:43:00 +04:00
// make checksum. we ignore back to back spaces so this
// hash works for <docsInCollection>10 vs <docsInCollection>9
2014-07-12 06:07:49 +04:00
long contentCRC = 0;
if ( content ) contentCRC = qa_hash32 ( content );
// note it
2014-07-27 05:43:11 +04:00
log("qa: got contentCRC of %lu",contentCRC);
2014-07-12 06:07:49 +04:00
// if what we expected, save to disk if not there yet, then
// call s_callback() to resume the qa pipeline
2014-07-27 05:43:11 +04:00
/*
2014-07-12 06:07:49 +04:00
if ( contentCRC == s_expectedCRC ) {
// save content if good
char fn3[1024];
2014-07-27 05:43:11 +04:00
sprintf(fn3,"%sqa/content.%lu",g_hostdb.m_dir,contentCRC);
File ff; ff.set ( fn3 );
if ( ! ff.doesExist() ) {
// if not there yet then save it
fb2.save(fn3);
}
// . continue on with the qa process
// . which qa function that may be
2014-07-11 20:45:34 +04:00
//s_callback();
return;
}
2014-07-27 05:43:11 +04:00
*/
2014-07-07 05:53:05 +04:00
//
2014-07-12 06:07:49 +04:00
// if crc of content does not match what was expected then do a diff
// so we can see why not
//
2014-07-11 19:35:20 +04:00
// this means caller does not care about the response
2014-07-29 06:15:31 +04:00
if ( ! s_checkCRC ) {
2014-07-11 20:45:34 +04:00
//s_callback();
2014-07-11 19:35:20 +04:00
return;
}
2014-07-27 05:43:11 +04:00
//const char *emsg = "qa: bad contentCRC of %li should be %li "
// "\n";//"phase=%li\n";
//fprintf(stderr,emsg,contentCRC,s_expectedCRC);//,s_phase-1);
// hash url
long urlHash32 = hash32n ( s_url.getUrl() );
2014-07-27 07:05:05 +04:00
// combine test function too since two tests may use the same url
long nameHash = hash32n ( s_qt->m_testName );
// combine together
urlHash32 = hash32h ( nameHash , urlHash32 );
makeQADir();
2014-07-27 05:43:11 +04:00
2014-07-29 08:29:11 +04:00
// break up into lines
char fn2[1024];
sprintf(fn2,"%sqa/content.%lu",g_hostdb.m_dir,contentCRC);
fb2.save ( fn2 );
2014-07-27 05:43:11 +04:00
// look up in hashtable to see what reply crc should be
long *val = (long *)s_ht.getValue ( &urlHash32 );
2014-07-29 06:15:31 +04:00
// just return if the same
if ( val && contentCRC == *val ) {
g_qaOutput.safePrintf("<b style=color:green;>"
"passed test</b><br>%s : "
2014-07-29 08:29:11 +04:00
"<a href=%s>%s</a> (urlhash=%lu "
2014-07-29 06:15:31 +04:00
"crc=<a href=/qa/content.%lu>"
"%lu</a>)<br>"
2014-07-27 08:39:16 +04:00
"<hr>",
s_qt->m_testName,
s_url.getUrl(),
2014-07-29 08:29:11 +04:00
s_url.getUrl(),
2014-07-27 08:39:16 +04:00
urlHash32,
contentCRC,
contentCRC);
2014-07-27 05:43:11 +04:00
return;
}
2014-07-29 06:15:31 +04:00
if ( ! val ) {
// add it so we know
s_ht.addKey ( &urlHash32 , &contentCRC );
g_qaOutput.safePrintf("<b style=color:blue;>"
"first time testing</b><br>%s : "
2014-07-29 08:29:11 +04:00
"<a href=%s>%s</a> "
"(urlhash=%lu "
2014-07-29 06:15:31 +04:00
"crc=<a href=/qa/content.%lu>%lu"
"</a>)<br>"
2014-07-27 05:43:11 +04:00
"<hr>",
2014-07-27 08:39:16 +04:00
s_qt->m_testName,
2014-07-27 05:43:11 +04:00
s_url.getUrl(),
2014-07-29 08:29:11 +04:00
s_url.getUrl(),
2014-07-27 05:43:11 +04:00
urlHash32,
contentCRC,
contentCRC);
return;
}
2014-07-29 06:15:31 +04:00
2014-07-27 05:43:11 +04:00
log("qa: crc changed for url %s from %li to %li",
s_url.getUrl(),*val,contentCRC);
// get response on file
SafeBuf fb1;
char fn1[1024];
2014-07-27 05:43:11 +04:00
sprintf(fn1,"%sqa/content.%lu",g_hostdb.m_dir, *val);
fb1.load(fn1);
fb1.nullTerm();
2014-07-27 05:43:11 +04:00
// do the diff between the two replies so we can see what changed
char cmd[1024];
2014-07-26 19:12:42 +04:00
sprintf(cmd,"diff %s %s > /tmp/diffout",fn1,fn2);
//log("qa: %s\n",cmd);
gbsystem(cmd);
2014-07-26 19:12:42 +04:00
2014-07-28 22:13:02 +04:00
g_numErrors++;
g_qaOutput.safePrintf("<b style=color:red;>FAILED TEST</b><br>%s : "
2014-07-29 08:29:11 +04:00
"<a href=%s>%s</a> (urlhash=%lu)<br>"
2014-07-27 05:43:11 +04:00
2014-07-28 22:13:02 +04:00
"<input type=checkbox name=urlhash%lu value=1 "
// use ajax to update test crc. if you undo your
// check then it should put the old val back.
// when you first click the checkbox it should
// gray out the diff i guess.
"onclick=submitchanges(%lu,%lu);> "
2014-07-27 05:43:11 +04:00
"Accept changes"
2014-07-27 07:05:05 +04:00
2014-07-27 05:43:11 +04:00
"<br>"
"original on left, new on right. "
2014-07-27 07:05:05 +04:00
"oldcrc = <a href=/qa/content.%lu>%lu</a>"
2014-07-28 22:13:02 +04:00
2014-07-27 07:05:05 +04:00
" != <a href=/qa/content.%lu>%lu</a> = newcrc"
2014-07-28 22:13:02 +04:00
"<br>diff output follows:<br>"
2014-07-29 06:15:31 +04:00
"<pre id=%lu style=background-color:0xffffff;>",
2014-07-27 08:39:16 +04:00
s_qt->m_testName,
2014-07-27 05:43:11 +04:00
s_url.getUrl(),
2014-07-29 08:29:11 +04:00
s_url.getUrl(),
2014-07-27 05:43:11 +04:00
urlHash32,
2014-07-28 22:13:02 +04:00
// input checkbox name field
2014-07-27 05:43:11 +04:00
urlHash32,
2014-07-28 22:13:02 +04:00
// submitchanges() parms
urlHash32,
contentCRC,
// original/old content.%lu
2014-07-27 07:05:05 +04:00
*val,
2014-07-27 05:43:11 +04:00
*val,
2014-07-28 22:13:02 +04:00
// new content.%lu
contentCRC,
contentCRC,
// for the pre tag id:
urlHash32);
2014-07-26 19:12:42 +04:00
// store in output
SafeBuf sb;
sb.load("/tmp/diffout");
g_qaOutput.htmlEncode ( sb.getBufStart() );
2014-07-29 06:15:31 +04:00
g_qaOutput.safePrintf("</pre><br><hr>");
2014-07-26 19:12:42 +04:00
// if this is zero allow it to slide by. it is learning mode i guess.
// so we can learn what crc we need to use.
// otherwise, stop right there for debugging
2014-07-26 19:12:42 +04:00
//if ( s_expectedCRC != 0 ) exit(1);
2014-07-07 05:53:05 +04:00
// keep on going
2014-07-11 20:45:34 +04:00
//s_callback();
}
// after we got the reply and verified expected crc, call the callback
static bool (*s_callback)() = NULL;
// come here after receiving ANY reply from the gigablast server
static void gotReplyWrapper ( void *state , TcpSocket *sock ) {
processReply ( sock->m_readBuf , sock->m_readOffset );
s_callback ();
}
2014-04-05 22:33:42 +04:00
2014-07-11 20:45:34 +04:00
// returns false if blocked, true otherwise, like on quick connect error
2014-07-29 06:15:31 +04:00
bool getUrl( char *path , long checkCRC = 0 , char *post = NULL ) {
2014-04-05 22:33:42 +04:00
SafeBuf sb;
sb.safePrintf ( "http://%s:%li%s"
, iptoa(g_hostdb.m_myHost->m_ip)
, (long)g_hostdb.m_myHost->m_httpPort
, path
);
2014-07-29 06:15:31 +04:00
s_checkCRC = checkCRC;
2014-07-27 08:39:16 +04:00
bool doPost = true;
if ( strncmp ( path , "/search" , 7 ) == 0 )
doPost = false;
2014-07-26 19:12:42 +04:00
//Url u;
s_url.set ( sb.getBufStart() );
log("qa: getting %s",sb.getBufStart());
2014-07-26 19:12:42 +04:00
if ( ! g_httpServer.getDoc ( s_url.getUrl() ,
0 , // ip
0 , // offset
-1 , // size
0 , // ifmodsince
NULL ,
gotReplyWrapper,
2014-07-27 07:05:05 +04:00
999999*1000, // timeout ms
0, // proxyip
0, // proxyport
-1, // maxtextdoclen
-1, // maxotherdoclen
NULL , // useragent
"HTTP/1.0" , // protocol
2014-07-27 08:39:16 +04:00
doPost , // doPost
NULL , // cookie
NULL , // additionalHeader
NULL , // fullRequest
post ) )
return false;
// error?
2014-07-11 20:45:34 +04:00
processReply ( NULL , 0 );
//log("qa: getUrl error: %s",mstrerror(g_errno));
return true;
}
2014-04-05 22:33:42 +04:00
bool loadUrls ( ) {
static bool s_loaded = false;
if ( s_loaded ) return true;
2014-07-07 02:04:21 +04:00
s_loaded = true;
2014-04-05 22:33:42 +04:00
// use injectme3 file
s_ubuf1.load("./injectme3");
// scan for +++URL: xxxxx
char *s = s_ubuf1.getBufStart();
for ( ; *s ; s++ ) {
if ( strncmp(s,"+++URL: ",8) ) continue;
// got one
2014-07-07 02:04:21 +04:00
// \0 term it for s_contentPtrs below
*s = '\0';
2014-04-05 22:33:42 +04:00
// find end of it
s += 8;
char *e = s;
for ( ; *e && ! is_wspace_a(*e); e++ );
// null term it
if ( *e ) *e = '\0';
// store ptr
s_ubuf2.pushLong((long)s);
// skip past that
s = e;
2014-07-07 02:04:21 +04:00
// point to content
s_cbuf2.pushLong((long)(s+1));
2014-04-05 22:33:42 +04:00
}
// make array of url ptrs
s_urlPtrs = (char **)s_ubuf2.getBufStart();
2014-07-07 02:04:21 +04:00
s_contentPtrs= (char **)s_cbuf2.getBufStart();
2014-04-05 22:33:42 +04:00
return true;
}
2014-07-07 03:47:04 +04:00
/*
2014-04-05 22:33:42 +04:00
static char *s_queries[] = {
"the",
"+the",
"cats",
"+cats dog",
"+cats +dog",
"cat OR dog",
"cat AND dog",
"cat AND NOT dog",
"NOT cat AND NOT dog",
"cat -dog",
"site:wisc.edu"
};
2014-07-07 03:47:04 +04:00
*/
2014-04-05 22:33:42 +04:00
2014-07-28 22:13:02 +04:00
//#undef usleep
2014-07-07 09:06:33 +04:00
2014-07-26 19:12:42 +04:00
// nw use this
static long *s_flags = NULL;
//
// the injection qa test suite
//
2014-07-26 19:12:42 +04:00
bool qainject1 ( ) {
2014-07-07 09:06:33 +04:00
2014-07-26 19:12:42 +04:00
//if ( ! s_callback ) s_callback = qainject1;
2014-07-09 07:33:13 +04:00
//
// delete the 'qatest123' collection
//
2014-07-26 19:12:42 +04:00
//static bool s_x1 = false;
if ( ! s_flags[0] ) {
s_flags[0] = true;
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( "/admin/delcoll?xml=1&delcoll=qatest123" ) )
return false;
2014-07-07 05:53:05 +04:00
}
2014-07-07 01:13:00 +04:00
//
2014-04-05 22:33:42 +04:00
// add the 'qatest123' collection
2014-07-07 01:13:00 +04:00
//
2014-07-26 19:12:42 +04:00
//static bool s_x2 = false;
if ( ! s_flags[1] ) {
s_flags[1] = true;
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( "/admin/addcoll?addcoll=qatest123&xml=1" ,
// checksum of reply expected
238170006 ) )
return false;
2014-07-07 01:13:00 +04:00
}
2014-04-05 22:33:42 +04:00
// turn off images thumbnails
if ( ! s_flags[17] ) {
s_flags[17] = true;
if ( ! getUrl ( "/admin/spider?c=qatest123&mit=0",
// checksum of reply expected
238170006 ) )
return false;
}
2014-07-27 05:43:11 +04:00
// this only loads once
loadUrls();
2014-07-26 19:12:42 +04:00
long max = s_ubuf2.length()/(long)sizeof(char *);
2014-07-27 05:43:11 +04:00
//max = 1;
2014-07-26 19:12:42 +04:00
2014-07-07 01:13:00 +04:00
//
2014-04-05 22:33:42 +04:00
// inject urls, return false if not done yet
2014-07-07 01:13:00 +04:00
//
2014-07-26 19:12:42 +04:00
//static bool s_x4 = false;
if ( ! s_flags[2] ) {
2014-07-07 01:13:00 +04:00
// TODO: try delimeter based injection too
2014-07-27 05:43:11 +04:00
//static long s_ii = 0;
for ( ; s_flags[20] < max ; ) {
2014-07-07 01:13:00 +04:00
// inject using html api
SafeBuf sb;
2014-07-07 09:06:33 +04:00
sb.safePrintf("&c=qatest123&deleteurl=0&"
2014-07-07 01:13:00 +04:00
"format=xml&u=");
2014-07-27 05:43:11 +04:00
sb.urlEncode ( s_urlPtrs[s_flags[20]] );
2014-07-07 02:04:21 +04:00
// the content
sb.safePrintf("&hasmime=1");
2014-08-07 03:00:25 +04:00
// sanity
//if ( strstr(s_urlPtrs[s_flags[20]],"wdc.htm") )
// log("hey");
2014-07-07 02:04:21 +04:00
sb.safePrintf("&content=");
2014-07-27 05:43:11 +04:00
sb.urlEncode(s_contentPtrs[s_flags[20]] );
2014-07-07 01:13:00 +04:00
sb.nullTerm();
2014-07-07 02:04:21 +04:00
// pre-inc it in case getUrl() blocks
2014-07-27 05:43:11 +04:00
s_flags[20]++;//ii++;
2014-07-11 20:45:34 +04:00
if ( ! getUrl("/admin/inject",
0, // no idea what crc to expect
sb.getBufStart()) )
return false;
2014-07-07 01:13:00 +04:00
}
2014-07-26 19:12:42 +04:00
s_flags[2] = true;
2014-07-07 01:13:00 +04:00
}
2014-07-07 03:47:04 +04:00
// +the
2014-07-26 19:12:42 +04:00
//static bool s_x5 = false;
if ( ! s_flags[3] ) {
2014-07-28 22:13:02 +04:00
wait(1.5);
2014-07-26 19:12:42 +04:00
s_flags[3] = true;
2014-07-28 22:13:02 +04:00
return false;
}
if ( ! s_flags[16] ) {
s_flags[16] = true;
2014-09-12 03:04:08 +04:00
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&q=%2Bthe"
"&dsrt=500",
2014-07-15 21:06:33 +04:00
702467314 ) )
2014-07-11 20:45:34 +04:00
return false;
2014-07-07 03:47:04 +04:00
}
2014-07-07 09:06:33 +04:00
2014-07-07 03:47:04 +04:00
// sports news
2014-07-26 19:12:42 +04:00
//static bool s_x7 = false;
if ( ! s_flags[4] ) {
s_flags[4] = true;
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&"
2014-07-15 21:06:33 +04:00
"q=sports+news",2009472889 ) )
2014-07-11 20:45:34 +04:00
return false;
2014-07-07 03:47:04 +04:00
}
2014-07-07 09:06:33 +04:00
// 'washer & dryer' does some algorithmic synonyms 'washer and dryer'
if ( ! s_flags[15] ) {
s_flags[15] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&"
"debug=1&q=washer+%26+dryer",9999 ) )
return false;
}
2014-07-07 05:53:05 +04:00
//
// eject/delete the urls
//
2014-07-26 19:12:42 +04:00
//static long s_ii2 = 0;
for ( ; s_flags[5] < max ; ) {
2014-07-07 05:53:05 +04:00
// reject using html api
SafeBuf sb;
sb.safePrintf( "/admin/inject?c=qatest123&deleteurl=1&"
"format=xml&u=");
2014-07-26 19:12:42 +04:00
sb.urlEncode ( s_urlPtrs[s_flags[5]] );
2014-07-07 05:53:05 +04:00
sb.nullTerm();
// pre-inc it in case getUrl() blocks
2014-07-26 19:12:42 +04:00
//s_ii2++;
s_flags[5]++;
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( sb.getBufStart() , 0 ) )
return false;
2014-07-07 05:53:05 +04:00
}
2014-07-07 03:47:04 +04:00
2014-07-07 05:53:05 +04:00
//
// make sure no results left, +the
//
2014-07-26 19:12:42 +04:00
if ( ! s_flags[6] ) {
2014-07-28 22:13:02 +04:00
wait(1.5);
2014-07-26 19:12:42 +04:00
s_flags[6] = true;
2014-07-28 22:13:02 +04:00
return false;
}
if ( ! s_flags[14] ) {
s_flags[14] = true;
2014-07-27 05:43:11 +04:00
if ( ! getUrl ( "/search?c=qatest123&qa=2&format=xml&q=%2Bthe",
2014-07-11 20:45:34 +04:00
-1672870556 ) )
return false;
2014-07-07 05:53:05 +04:00
}
2014-07-07 09:06:33 +04:00
2014-07-27 05:43:11 +04:00
//static bool s_fee2 = false;
if ( ! s_flags[13] ) {
s_flags[13] = true;
log("qa: SUCCESSFULLY COMPLETED "
"QA INJECT TEST 1");
//if ( s_callback == qainject ) exit(0);
return true;
}
2014-07-26 19:12:42 +04:00
return true;
}
bool qainject2 ( ) {
//if ( ! s_callback ) s_callback = qainject2;
//
// delete the 'qatest123' collection
//
//static bool s_x1 = false;
if ( ! s_flags[0] ) {
s_flags[0] = true;
if ( ! getUrl ( "/admin/delcoll?xml=1&delcoll=qatest123" ) )
return false;
}
//
// add the 'qatest123' collection
//
//static bool s_x2 = false;
if ( ! s_flags[1] ) {
s_flags[1] = true;
if ( ! getUrl ( "/admin/addcoll?addcoll=qatest123&xml=1" ,
// checksum of reply expected
238170006 ) )
return false;
}
// turn off images thumbnails
if ( ! s_flags[17] ) {
s_flags[17] = true;
if ( ! getUrl ( "/admin/spider?c=qatest123&mit=0",
// checksum of reply expected
238170006 ) )
return false;
}
2014-07-07 09:06:33 +04:00
//
// try delimeter based injecting
//
2014-07-26 19:12:42 +04:00
//static bool s_y2 = false;
if ( ! s_flags[7] ) {
s_flags[7] = true;
2014-07-07 09:06:33 +04:00
SafeBuf sb;
// delim=+++URL:
sb.safePrintf("&c=qatest123&deleteurl=0&"
"delim=%%2B%%2B%%2BURL%%3A&format=xml&u=xyz.com&"
"hasmime=1&content=");
// use injectme3 file
SafeBuf ubuf;
ubuf.load("./injectme3");
sb.urlEncode(ubuf.getBufStart());
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( "/admin/inject",
// check reply, seems to have only a single
// docid in it
-1970198487, sb.getBufStart()) )
return false;
2014-07-07 09:06:33 +04:00
}
// now query check
2014-07-26 19:12:42 +04:00
//static bool s_y4 = false;
if ( ! s_flags[8] ) {
2014-07-28 22:13:02 +04:00
wait(1.5);
2014-07-26 19:12:42 +04:00
s_flags[8] = true;
2014-07-28 22:13:02 +04:00
return false;
}
if ( ! s_flags[14] ) {
s_flags[14] = true;
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&q=%2Bthe",
2014-07-15 21:06:33 +04:00
-1804253505 ) )
2014-07-11 20:45:34 +04:00
return false;
2014-07-07 09:06:33 +04:00
}
2014-07-26 19:12:42 +04:00
//static bool s_y5 = false;
if ( ! s_flags[9] ) {
s_flags[9] = true;
2014-07-13 03:47:32 +04:00
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&q=sports"
"+news&ns=1&tml=20&smxcpl=30&"
"sw=10&showimages=1"
2014-07-15 21:06:33 +04:00
,-1874756636 ) )
2014-07-13 03:47:32 +04:00
return false;
}
2014-07-26 19:12:42 +04:00
//static bool s_y6 = false;
if ( ! s_flags[10] ) {
s_flags[10] = true;
2014-07-13 03:47:32 +04:00
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&q=sports"
"+news&ns=1&tml=20&smxcpl=30&"
"sw=10&showimages=0&hacr=1"
2014-07-15 21:06:33 +04:00
,1651330319 ) )
2014-07-13 03:47:32 +04:00
return false;
}
2014-07-26 19:12:42 +04:00
//static bool s_y7 = false;
if ( ! s_flags[11] ) {
s_flags[11] = true;
2014-07-13 03:47:32 +04:00
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&q=sports"
"+news&ns=1&tml=20&smxcpl=30&"
"sw=10&showimages=0&sc=1"
2014-07-15 21:06:33 +04:00
,-1405546537 ) )
2014-07-13 03:47:32 +04:00
return false;
}
//
// mdw: query reindex test
//
if ( ! s_flags[30] ) {
s_flags[30] = true;
if ( ! getUrl ( "/admin/reindex"
"?c=qatest123"
"&format=xml"
//"&debug=1"
"&q=sports"
"&forcedel=1"
"&qa=1"
,9999 ) )
return false;
}
// wait 10 seconds for reindex to finish
if ( ! s_flags[31] ) {
wait(10.0);
s_flags[31] = true;
return false;
}
// ensure no results for sports now
if ( ! s_flags[32] ) {
s_flags[32] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&q=sports"
"&ns=1&tml=20&smxcpl=30&"
"sw=10&showimages=0&sc=1"
,-1405546537 ) )
2014-07-11 20:45:34 +04:00
return false;
2014-07-07 05:53:05 +04:00
}
// and this particular url has two spider status records indexed
if ( ! s_flags[33] ) {
s_flags[33] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&q="
"url2%3Axyz.com%2F-13737921970569011262&xml=1"
,-1405546537 ) )
return false;
}
//
// delete the 'qatest123' collection
//
// if ( ! s_flags[12] ) {
// s_flags[12] = true;
// if ( ! getUrl ( "/admin/delcoll?xml=1&delcoll=qatest123" ) )
// return false;
// }
2014-07-26 19:12:42 +04:00
//static bool s_fee2 = false;
if ( ! s_flags[13] ) {
s_flags[13] = true;
2014-07-27 07:05:05 +04:00
log("qa: SUCCESSFULLY COMPLETED "
"QA INJECT TEST 2");
2014-07-26 19:12:42 +04:00
//if ( s_callback == qainject ) exit(0);
2014-07-09 07:33:13 +04:00
return true;
}
return true;
}
bool qaimport () {
//if ( ! s_callback ) s_callback = qainject1;
//
// delete the 'qatest123' collection
//
//static bool s_x1 = false;
if ( ! s_flags[0] ) {
s_flags[0] = true;
if ( ! getUrl ( "/admin/delcoll?xml=1&delcoll=qatest123" ) )
return false;
}
//
// add the 'qatest123' collection
//
//static bool s_x2 = false;
if ( ! s_flags[1] ) {
s_flags[1] = true;
if ( ! getUrl ( "/admin/addcoll?addcoll=qatest123&xml=1" ,
// checksum of reply expected
238170006 ) )
return false;
}
// turn spiders off so it doesn't spider while we are importing
if ( ! s_flags[18] ) {
s_flags[18] = true;
if ( ! getUrl ( "/admin/spider?cse=0&c=qatest123",
// checksum of reply expected
238170006 ) )
return false;
}
// set the import dir and # inject threads
if ( ! s_flags[17] ) {
s_flags[17] = true;
if ( ! getUrl ( "/admin/import?c=qatest123&importdir=%2Fhome%2Fmwells%2Ftesting%2Fimport%2F&numimportinjects=3&import=1&action=submit",
// checksum of reply expected
238170006 ) )
return false;
}
// wait for importloop to "kick in" so it can set cr->m_importState
if ( ! s_flags[3] ) {
wait(1.0);
s_flags[3] = true;
return false;
}
// import must be done!
if ( ! s_flags[19] ) {
CollectionRec *cr = g_collectiondb.getRec("qatest123");
// if still importing this will be non-null
if ( cr->m_importState ) {
wait(1.0);
return false;
}
// all done then
s_flags[19] = true;
}
// test query
if ( ! s_flags[16] ) {
s_flags[16] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&q=%2Bthe"
"&dsrt=500",
702467314 ) )
return false;
}
//static bool s_fee2 = false;
if ( ! s_flags[13] ) {
s_flags[13] = true;
log("qa: SUCCESSFULLY COMPLETED DATA "
"IMPORT TEST");
//if ( s_callback == qainject ) exit(0);
return true;
}
return true;
}
2014-07-28 22:13:02 +04:00
/*
2014-07-09 07:33:13 +04:00
static char *s_urls1 =
2014-07-11 03:42:22 +04:00
" walmart.com"
" cisco.com"
" t7online.com"
" sonyericsson.com"
" netsh.com"
" allegro.pl"
" hotscripts.com"
" sitepoint.com"
" so-net.net.tw"
" aol.co.uk"
" sbs.co.kr"
" chinaacc.com"
" eyou.com"
" spray.se"
" carview.co.jp"
" xcar.com.cn"
" united.com"
" raaga.com"
" primaryads.com"
" szonline.net"
" icbc.com.cn"
" instantbuzz.com"
" sz.net.cn"
" 6to23.com"
" seesaa.net"
" tracking101.com"
" jubii.dk"
" 5566.net"
" prikpagina.nl"
" 7xi.net"
" 91.com"
" jjwxc.com"
" adbrite.com"
" hoplay.com"
" questionmarket.com"
" telegraph.co.uk"
" trendmicro.com"
" google.fi"
" ebay.es"
" tfol.com"
" sleazydream.com"
" websearch.com"
" freett.com"
" dayoo.com"
" interia.pl"
" yymp3.com"
" stanford.edu"
" time.gr.jp"
" telia.com"
" madthumbs.com"
" chinamp3.com"
" oldgames.se"
" buy.com"
" singpao.com"
" cbsnews.com"
" corriere.it"
" cbs.com"
" flickr.com"
" theglobeandmail.com"
" incredifind.com"
" mit.edu"
" chase.com"
" ktv666.com"
" oldnavy.com"
" lego.com"
" eniro.se"
" bloomberg.com"
" ft.com"
" odn.ne.jp"
" pcpop.com"
" ugameasia.com"
" cantv.net"
" allinternal.com"
" aventertainments.com"
" invisionfree.com"
" hangzhou.com.cn"
" zhaopin.com"
" bcentral.com"
" lowes.com"
" adprofile.net"
" yninfo.com"
" jeeran.com"
" twbbs.net.tw"
" yousendit.com"
" aavalue.com"
" google.com.co"
" mysearch.com"
" worldsex.com"
" navisearch.net"
" lele.com"
" msn.co.in"
" officedepot.com"
" xintv.com"
" 204.177.92.193"
" travelzoo.com"
" bol.com.br"
" dtiserv2.com"
" optonline.net"
" hitslink.com"
" freechal.com"
" infojobs.net"
2014-07-09 07:33:13 +04:00
;
2014-07-28 22:13:02 +04:00
*/
2014-07-09 07:33:13 +04:00
2014-07-14 18:13:55 +04:00
bool qaspider1 ( ) {
//
// delete the 'qatest123' collection
//
2014-07-26 19:12:42 +04:00
//static bool s_x1 = false;
if ( ! s_flags[0] ) {
s_flags[0] = true;
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( "/admin/delcoll?xml=1&delcoll=qatest123" ) )
return false;
2014-07-09 07:33:13 +04:00
}
//
// add the 'qatest123' collection
//
2014-07-26 19:12:42 +04:00
//static bool s_x2 = false;
if ( ! s_flags[1] ) {
s_flags[1] = true;
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( "/admin/addcoll?addcoll=qatest123&xml=1" ,
// checksum of reply expected
238170006 ) )
return false;
2014-07-09 07:33:13 +04:00
}
// turn off images thumbnails
if ( ! s_flags[24] ) {
s_flags[24] = true;
if ( ! getUrl ( "/admin/spider?c=qatest123&mit=0",
// checksum of reply expected
238170006 ) )
return false;
}
2014-07-11 19:00:30 +04:00
// restrict hopcount to 0 or 1 in url filters so we do not spider
// too deep
2014-07-26 19:12:42 +04:00
//static bool s_z1 = false;
if ( ! s_flags[2] ) {
s_flags[2] = true;
2014-07-09 07:33:13 +04:00
SafeBuf sb;
2014-07-11 19:00:30 +04:00
sb.safePrintf("&c=qatest123&"
// make it the custom filter
"ufp=custom&"
2014-07-11 19:00:30 +04:00
"fe=%%21ismanualadd+%%26%%26+%%21insitelist&hspl=0&hspl=1&fsf=0.000000&mspr=0&mspi=1&xg=1000&fsp=-3&"
2014-07-11 19:00:30 +04:00
// take out hopcount for now, just test quotas
// "fe1=tag%%3Ashallow+%%26%%26+hopcount%%3C%%3D1&hspl1=0&hspl1=1&fsf1=1.000000&mspr1=1&mspi1=1&xg1=1000&fsp1=3&"
2014-08-02 20:07:33 +04:00
// just one spider out allowed for consistency
2014-07-11 19:00:30 +04:00
"fe1=tag%%3Ashallow+%%26%%26+sitepages%%3C%%3D20&hspl1=0&hspl1=1&fsf1=1.000000&mspr1=1&mspi1=1&xg1=1000&fsp1=45&"
2014-07-11 19:00:30 +04:00
"fe2=default&hspl2=0&hspl2=1&fsf2=1.000000&mspr2=0&mspi2=1&xg2=1000&fsp2=45&"
2014-07-11 19:00:30 +04:00
);
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( "/admin/filters",0,sb.getBufStart()) )
return false;
}
2014-07-11 19:00:30 +04:00
// set the site list to
// a few sites
2014-07-26 19:12:42 +04:00
//static bool s_z2 = false;
if ( ! s_flags[3] ) {
s_flags[3] = true;
2014-07-11 03:28:24 +04:00
SafeBuf sb;
2014-07-11 19:00:30 +04:00
sb.safePrintf("&c=qatest123&format=xml&sitelist=");
2014-07-14 18:13:55 +04:00
sb.urlEncode("tag:shallow site:www.walmart.com\r\n"
"tag:shallow site:http://www.ibm.com/\r\n");
2014-07-11 19:00:30 +04:00
sb.nullTerm();
2014-07-11 20:45:34 +04:00
if ( ! getUrl ("/admin/settings",0,sb.getBufStart() ) )
return false;
2014-07-11 03:28:24 +04:00
}
2014-07-11 19:00:30 +04:00
//
2014-07-11 19:00:30 +04:00
// use the add url interface now
// walmart.com above was not seeded because of the site: directive
// so this will seed it.
//
2014-07-26 19:12:42 +04:00
//static bool s_y2 = false;
if ( ! s_flags[4] ) {
s_flags[4] = true;
2014-07-11 03:28:24 +04:00
SafeBuf sb;
// delim=+++URL:
sb.safePrintf("&c=qatest123"
"&format=json"
"&strip=1"
"&spiderlinks=1"
2014-07-11 19:00:30 +04:00
"&urls=www.walmart.com+ibm.com"
2014-07-11 03:28:24 +04:00
);
// . now a list of websites we want to spider
// . the space is already encoded as +
2014-07-11 19:00:30 +04:00
//sb.urlEncode(s_urls1);
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( "/admin/addurl",0,sb.getBufStart()) )
return false;
2014-07-11 03:28:24 +04:00
}
2014-07-11 19:00:30 +04:00
//
// wait for spidering to stop
//
2014-07-11 03:42:22 +04:00
checkagain:
// wait until spider finishes. check the spider status page
// in json to see when completed
2014-07-26 19:12:42 +04:00
//static bool s_k1 = false;
if ( ! s_flags[5] ) {
2014-07-27 08:39:16 +04:00
// wait 5 seconds, call sleep timer... then call qatest()
//usleep(5000000); // 5 seconds
wait(3.0);
2014-07-26 19:12:42 +04:00
s_flags[5] = true;
2014-07-28 22:13:02 +04:00
return false;
}
if ( ! s_flags[15] ) {
s_flags[15] = true;
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( "/admin/status?format=json&c=qatest123",0) )
return false;
2014-07-11 03:42:22 +04:00
}
2014-07-26 19:12:42 +04:00
//static bool s_k2 = false;
if ( ! s_flags[6] ) {
2014-07-11 19:35:20 +04:00
// ensure spiders are done.
// "Nothing currently available to spider"
2014-07-12 06:07:49 +04:00
if ( s_content&&!strstr(s_content,"Nothing currently avail")){
2014-07-26 19:12:42 +04:00
s_flags[5] = false;
2014-07-28 22:13:02 +04:00
s_flags[15] = false;
2014-07-11 03:42:22 +04:00
goto checkagain;
}
2014-07-26 19:12:42 +04:00
s_flags[6] = true;
2014-07-11 03:42:22 +04:00
}
2014-07-11 19:00:30 +04:00
2014-08-02 20:07:33 +04:00
// wait for index msg4 to not be cached to ensure all results indexed
if ( ! s_flags[22] ) {
s_flags[22] = true;
wait(1.5);
}
2014-07-11 19:00:30 +04:00
2014-07-11 03:42:22 +04:00
2014-07-11 20:45:34 +04:00
// verify no results for gbhopcount:2 query
2014-07-26 19:12:42 +04:00
//static bool s_y4 = false;
if ( ! s_flags[7] ) {
s_flags[7] = true;
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&"
"q=gbhopcount%3A2",
-1672870556 ) )
return false;
}
// but some for gbhopcount:0 query
2014-07-26 19:12:42 +04:00
//static bool s_t0 = false;
if ( ! s_flags[8] ) {
s_flags[8] = true;
2014-07-11 20:45:34 +04:00
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&"
"q=gbhopcount%3A0",
2014-07-15 21:06:33 +04:00
908338607 ) )
2014-07-11 20:45:34 +04:00
return false;
2014-07-11 03:28:24 +04:00
}
// check facet sections query for walmart
2014-07-26 19:12:42 +04:00
//static bool s_y5 = false;
if ( ! s_flags[9] ) {
s_flags[9] = true;
if ( ! getUrl ( "/search?c=qatest123&format=json&stream=1&"
2014-07-11 20:45:34 +04:00
"q=gbfacetstr%3Agbxpathsitehash2492664135",
2014-07-15 21:06:33 +04:00
55157060 ) )
2014-07-11 20:45:34 +04:00
return false;
}
2014-07-26 19:12:42 +04:00
//static bool s_y6 = false;
if ( ! s_flags[10] ) {
s_flags[10] = true;
2014-07-29 08:29:11 +04:00
if ( ! getUrl ( "/get?page=4&q=gbfacetstr:gbxpathsitehash2492664135&qlang=xx&c=qatest123&d=9861563119&cnsp=0" , 999 ) )
2014-07-11 20:45:34 +04:00
return false;
2014-07-11 03:28:24 +04:00
}
2014-07-11 03:28:24 +04:00
// in xml
2014-07-26 19:12:42 +04:00
//static bool s_y7 = false;
if ( ! s_flags[11] ) {
s_flags[11] = true;
2014-07-29 06:15:31 +04:00
if ( ! getUrl ( "/get?xml=1&page=4&q=gbfacetstr:gbxpathsitehash2492664135&qlang=xx&c=qatest123&d=9861563119&cnsp=0" , 999 ) )
2014-07-11 20:45:34 +04:00
return false;
2014-07-11 03:28:24 +04:00
}
2014-07-11 03:28:24 +04:00
// and json
2014-07-26 19:12:42 +04:00
//static bool s_y8 = false;
if ( ! s_flags[12] ) {
s_flags[12] = true;
2014-07-29 08:29:11 +04:00
if ( ! getUrl ( "/get?json=1&page=4&q=gbfacetstr:gbxpathsitehash2492664135&qlang=xx&c=qatest123&d=9861563119&cnsp=0" , 999 ) )
2014-07-11 20:45:34 +04:00
return false;
2014-07-11 03:28:24 +04:00
}
2014-07-11 19:00:30 +04:00
// delete the collection
2014-07-26 19:12:42 +04:00
//static bool s_fee = false;
2014-07-29 06:15:31 +04:00
// if ( ! s_flags[13] ) {
// s_flags[13] = true;
// if ( ! getUrl ( "/admin/delcoll?delcoll=qatest123" ) )
// return false;
// }
if ( ! s_flags[17] ) {
s_flags[17] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&"
"q=site2%3Awww.walmart.com+"
"gbsortby%3Agbspiderdate",
999 ) )
2014-07-11 20:45:34 +04:00
return false;
2014-07-11 19:00:30 +04:00
}
2014-07-29 06:15:31 +04:00
// xpath is like a title here i think. check the returned
// facet table in the left column
if ( ! s_flags[18] ) {
s_flags[18] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=html&"
2014-07-31 04:00:33 +04:00
"q=gbfacetstr%3Agbxpathsitehash3624590799"
, 999 ) )
return false;
}
if ( ! s_flags[19] ) {
s_flags[19] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&xml=1&"
"q=gbfacetint%3Agbhopcount"
, 999 ) )
return false;
}
if ( ! s_flags[20] ) {
s_flags[20] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&json=1&"
"q=gbfacetint%3Alog.score"
, 999 ) )
return false;
}
2014-07-11 19:00:30 +04:00
2014-07-31 18:04:20 +04:00
if ( ! s_flags[21] ) {
s_flags[21] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&xml=1&"
"q=gbfacetfloat%3Atalks.rating"
, 999 ) )
return false;
}
2014-08-04 04:25:22 +04:00
if ( ! s_flags[23] ) {
s_flags[23] = true;
// test facets mixed with gigabits in left hand column
if ( ! getUrl ( "/search?c=qatest123&qa=1&html=1&"
"q=gbfacetint%3Agbhopcount+walmart"
, 999 ) )
return false;
}
2014-07-31 18:04:20 +04:00
2014-07-26 19:12:42 +04:00
//static bool s_fee2 = false;
if ( ! s_flags[14] ) {
s_flags[14] = true;
2014-07-29 06:15:31 +04:00
log("qa: SUCCESSFULLY COMPLETED "
"QA SPIDER1 TEST");
2014-07-11 19:00:30 +04:00
return true;
}
2014-07-11 19:00:30 +04:00
2014-04-05 22:33:42 +04:00
return true;
}
2014-07-14 18:13:55 +04:00
bool qaspider2 ( ) {
2014-07-14 18:13:55 +04:00
//
// delete the 'qatest123' collection
//
2014-07-26 19:12:42 +04:00
//static bool s_x1 = false;
if ( ! s_flags[0] ) {
s_flags[0] = true;
2014-07-14 18:13:55 +04:00
if ( ! getUrl ( "/admin/delcoll?xml=1&delcoll=qatest123" ) )
return false;
}
//
// add the 'qatest123' collection
//
2014-07-26 19:12:42 +04:00
//static bool s_x2 = false;
if ( ! s_flags[1] ) {
s_flags[1] = true;
2014-07-14 18:13:55 +04:00
if ( ! getUrl ( "/admin/addcoll?addcoll=qatest123&xml=1" ,
// checksum of reply expected
238170006 ) )
return false;
}
// turn off images thumbnails
if ( ! s_flags[24] ) {
s_flags[24] = true;
if ( ! getUrl ( "/admin/spider?c=qatest123&mit=0",
// checksum of reply expected
238170006 ) )
return false;
}
2014-07-14 18:13:55 +04:00
// restrict hopcount to 0 or 1 in url filters so we do not spider
// too deep
2014-07-26 19:12:42 +04:00
//static bool s_z1 = false;
if ( ! s_flags[2] ) {
s_flags[2] = true;
2014-07-14 18:13:55 +04:00
SafeBuf sb;
sb.safePrintf("&c=qatest123&"
// make it the custom filter
"ufp=custom&"
2014-07-14 18:13:55 +04:00
"fe=%%21ismanualadd+%%26%%26+%%21insitelist&hspl=0&hspl=1&fsf=0.000000&mspr=0&mspi=1&xg=1000&fsp=-3&"
// take out hopcount for now, just test quotas
// "fe1=tag%%3Ashallow+%%26%%26+hopcount%%3C%%3D1&hspl1=0&hspl1=1&fsf1=1.000000&mspr1=1&mspi1=1&xg1=1000&fsp1=3&"
2014-07-14 23:44:32 +04:00
// sitepages is a little fuzzy so take it
// out for this test and use hopcount!!!
//"fe1=tag%%3Ashallow+%%26%%26+sitepages%%3C%%3D20&hspl1=0&hspl1=1&fsf1=1.000000&mspr1=1&mspi1=1&xg1=1000&fsp1=45&"
"fe1=tag%%3Ashallow+%%26%%26+hopcount<%%3D1&hspl1=0&hspl1=1&fsf1=1.000000&mspr1=1&mspi1=1&xg1=1000&fsp1=45&"
2014-07-14 18:13:55 +04:00
"fe2=default&hspl2=0&hspl2=1&fsf2=1.000000&mspr2=0&mspi2=1&xg2=1000&fsp2=45&"
);
if ( ! getUrl ( "/admin/filters",0,sb.getBufStart()) )
return false;
}
// set the site list to
// a few sites
// these should auto seed so no need to use addurl
2014-07-26 19:12:42 +04:00
//static bool s_z2 = false;
if ( ! s_flags[3] ) {
s_flags[3] = true;
2014-07-14 18:13:55 +04:00
SafeBuf sb;
sb.safePrintf("&c=qatest123&format=xml&sitelist=");
2014-07-29 06:15:31 +04:00
sb.urlEncode(//walmart has too many pages at depth 1, so remove it
//"tag:shallow www.walmart.com\r\n"
2014-07-14 18:13:55 +04:00
"tag:shallow http://www.ibm.com/\r\n");
sb.nullTerm();
if ( ! getUrl ("/admin/settings",0,sb.getBufStart() ) )
return false;
}
//
// wait for spidering to stop
//
checkagain:
// wait until spider finishes. check the spider status page
// in json to see when completed
2014-07-26 19:12:42 +04:00
//static bool s_k1 = false;
if ( ! s_flags[4] ) {
2014-07-28 22:13:02 +04:00
//usleep(5000000); // 5 seconds
2014-07-26 19:12:42 +04:00
s_flags[4] = true;
wait(3.0);
2014-07-28 22:13:02 +04:00
return false;
}
if ( ! s_flags[14] ) {
s_flags[14] = true;
2014-07-14 18:13:55 +04:00
if ( ! getUrl ( "/admin/status?format=json&c=qatest123",0) )
return false;
}
2014-07-26 19:12:42 +04:00
//static bool s_k2 = false;
if ( ! s_flags[5] ) {
2014-07-14 18:13:55 +04:00
// ensure spiders are done.
// "Nothing currently available to spider"
if ( s_content&&!strstr(s_content,"Nothing currently avail")){
2014-07-26 19:12:42 +04:00
s_flags[4] = false;
2014-07-28 22:13:02 +04:00
s_flags[14] = false;
2014-07-14 18:13:55 +04:00
goto checkagain;
}
2014-07-26 19:12:42 +04:00
s_flags[5] = true;
2014-07-14 18:13:55 +04:00
}
// verify no results for gbhopcount:2 query
2014-07-26 19:12:42 +04:00
//static bool s_y4 = false;
if ( ! s_flags[6] ) {
s_flags[6] = true;
2014-07-14 18:13:55 +04:00
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&"
"q=gbhopcount%3A2",
2014-07-14 23:44:32 +04:00
-1310551262 ) )
2014-07-14 18:13:55 +04:00
return false;
}
// but some for gbhopcount:0 query
2014-07-26 19:12:42 +04:00
//static bool s_t0 = false;
if ( ! s_flags[7] ) {
s_flags[7] = true;
2014-07-15 21:06:33 +04:00
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&n=500&"
2014-07-14 18:13:55 +04:00
"q=gbhopcount%3A0",
2014-07-29 06:15:31 +04:00
999 ) )
2014-07-14 18:13:55 +04:00
return false;
}
// check facet sections query for walmart
2014-07-26 19:12:42 +04:00
//static bool s_y5 = false;
if ( ! s_flags[8] ) {
s_flags[8] = true;
if ( ! getUrl ( "/search?c=qatest123&format=json&stream=0&"
2014-07-29 08:29:11 +04:00
"q=gbfacetstr%3Agbxpathsitehash3311332088",
2014-07-29 06:15:31 +04:00
999 ) )
2014-07-14 18:13:55 +04:00
return false;
}
2014-08-02 20:07:33 +04:00
// wait for some reason
if ( ! s_flags[15] ) {
s_flags[15] = true;
wait(1.5);
return false;
}
2014-07-26 19:12:42 +04:00
//static bool s_y6 = false;
// 102573507011 docid is
// http://www.ibm.com/smarterplanet/us/en/overview/ideas/
2014-07-26 19:12:42 +04:00
if ( ! s_flags[9] ) {
s_flags[9] = true;
if ( ! getUrl ( "/get?page=4&q=gbfacetstr:gbxpathsitehash3311332088&qlang=xx&c=qatest123&d=102573507011&cnsp=0" , 999 ) )
2014-07-14 18:13:55 +04:00
return false;
}
// in xml
2014-07-26 19:12:42 +04:00
//static bool s_y7 = false;
if ( ! s_flags[10] ) {
s_flags[10] = true;
if ( ! getUrl ( "/get?xml=1&page=4&q=gbfacetstr:gbxpathsitehash2492664135&qlang=xx&c=qatest123&d=102573507011&cnsp=0" , 999 ) )
2014-07-14 18:13:55 +04:00
return false;
}
// and json
2014-07-26 19:12:42 +04:00
//static bool s_y8 = false;
if ( ! s_flags[11] ) {
s_flags[11] = true;
if ( ! getUrl ( "/get?json=1&page=4&q=gbfacetstr:gbxpathsitehash2492664135&qlang=xx&c=qatest123&d=102573507011&cnsp=0" , 999 ) )
2014-07-14 18:13:55 +04:00
return false;
}
// delete the collection
2014-07-26 19:12:42 +04:00
//static bool s_fee = false;
2014-07-29 08:29:11 +04:00
// if ( ! s_flags[12] ) {
// s_flags[12] = true;
// if ( ! getUrl ( "/admin/delcoll?delcoll=qatest123" ) )
// return false;
// }
2014-07-14 18:13:55 +04:00
2014-07-26 19:12:42 +04:00
//static bool s_fee2 = false;
if ( ! s_flags[13] ) {
s_flags[13] = true;
2014-07-29 06:15:31 +04:00
log("qa: SUCCESSFULLY COMPLETED "
"QA SPIDER2 TEST");
2014-07-14 18:13:55 +04:00
return true;
}
return true;
}
2014-07-30 06:51:41 +04:00
bool qascrape ( ) {
//
// delete the 'qatest123' collection
//
//static bool s_x1 = false;
if ( ! s_flags[0] ) {
s_flags[0] = true;
if ( ! getUrl ( "/admin/delcoll?xml=1&delcoll=qatest123" ) )
return false;
}
//
// add the 'qatest123' collection
//
//static bool s_x2 = false;
if ( ! s_flags[1] ) {
s_flags[1] = true;
if ( ! getUrl ( "/admin/addcoll?addcoll=qatest123&xml=1" ,
// checksum of reply expected
238170006 ) )
return false;
}
// turn off images thumbnails
if ( ! s_flags[24] ) {
s_flags[24] = true;
if ( ! getUrl ( "/admin/spider?c=qatest123&mit=0",
// checksum of reply expected
238170006 ) )
return false;
}
2014-07-30 06:51:41 +04:00
// scrape it
if ( ! s_flags[3] ) {
s_flags[3] = true;
SafeBuf sb;
sb.safePrintf( "/admin/inject?c=qatest123&"
"format=xml&qts=test");
if ( ! getUrl ( sb.getBufStart() , 999 ) )
2014-07-30 06:51:41 +04:00
return false;
}
// verify no results for gbhopcount:2 query
//static bool s_y4 = false;
if ( ! s_flags[6] ) {
s_flags[6] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&"
"q=test",
-1310551262 ) )
return false;
}
//static bool s_fee2 = false;
if ( ! s_flags[13] ) {
s_flags[13] = true;
log("qa: SUCCESSFULLY COMPLETED "
"QA SCRAPE TEST");
return true;
}
return true;
}
static char *s_ubuf4 =
"http://www.nortel.com/multimedia/flash/mediaplayer/config/solutions_enterprisesecurity.json "
"http://quirksmode.org/m/d/md.json "
"http://www.chip.de/headfoot/json/8659753/tk.json?t=11-02-08-13-32 "
"http://developer.apple.com/wwdc/data/sessions.json "
"http://www.bbc.co.uk/radio4/programmes/schedules/fm/today.json "
"http://www.hellonorthgeorgia.com/slideShowJSON11034.json "
"http://www.metastatic.org/log-4.json "
"http://www.metastatic.org/log.json "
"http://www.textsfromlastnight.com/Vote-Down-Text-24266.json "
"http://www.textsfromlastnight.com/Vote-Up-Text-13999.json "
"http://shapewiki.com/shapes/4755.json "
"http://shapewiki.com/shapes/40.json "
"http://www.neocol.com/news/hcc-international-appoint-neocol-as-information-management-partner.json "
"http://www.bbc.co.uk/programmes/b00vy3l1.json "
"http://iwakura.clipp.in/feed.json "
"http://schwarzlich.clipp.in/feed.json "
"http://freethefoxes.googlecode.com/svn/trunk/lang/sv.json "
"http://www.domik.net/data/vCard1.json "
"http://www.domik.net/data/vCard14205.json "
"http://www.chip.de/headfoot/json/8659753/handy.json?t=11-02-08-13-32 "
"http://www.neocol.com/news/neocol-relocates-to-new-expanded-hq.json "
"http://www.nbafinals.com/video/channels/nba_tv/2009/07/23/nba_20090723_1fab5_pistons.nba.json "
"http://quiltid.com/feeds/me/blake.json "
"http://parliament.southgatelabs.com/members.json "
"http://www.funradio.fr/service/carrousel.json?home "
"http://doyouflip.com/dcefd5cffeecebcabc049a8a1cc18fac/bundle.json "
"http://freethefoxes.googlecode.com/svn/trunk/lang/sch.json "
"http://delphie.clipp.in/feed.json "
"http://gotgastro.com/notices.json "
"http://www.paralela45bacau.ro/ajax/newsletter.json "
"http://www.elstoleno.com/unsorted.json "
"http://papanda.clipp.in/feed.json "
"http://d.yimg.com/b/api/data/us/news/elections/2010/result/us_house.json "
"http://www.nba.co.nz/video/teams/sixers/2009/07/28/090727lou.sixers.json "
"http://n2.talis.com/svn/playground/mmmmmrob/OpenLibrary/tags/day1/data/authors.1in10.json "
"http://asn.jesandco.org/resources/D2364040_manifest.json "
"http://search.twitter.com/search.json?q=from%3ADrathal "
"http://www.matthiresmusic.com/3f6524261baf47acc61d3fb22ab9b18a/bundle.json "
"http://search.twitter.com/search.json?q= "
"http://www.christinaperri.com/98a59708246eb4fcc4e22a09113699c6/bundle.json "
"http://www.misterbluesky.nl/News.json "
"http://ymorimo.clipp.in/feed.json "
"http://wedata.net/databases.json "
"http://cms.myspacecdn.com/cms/api/opensearch.json "
"http://seria.clipp.in/feed.json "
"http://www.treysongz.com/6b10fcf3a6f99b4622e4d33d1532b380/bundle.json "
"http://psychedesire.clipp.in/feed.json "
"http://www.sekaino.com/skedu/demodata/dev_data_ccmixter.json "
"http://www.360wichita.com/slideShowJSON8496.json "
"http://speakerrate.com/events/856-jquery-conference-2011-san-francisco-bay-area.json "
;
bool qajson ( ) {
//
// delete the 'qatest123' collection
//
//static bool s_x1 = false;
if ( ! s_flags[0] ) {
s_flags[0] = true;
if ( ! getUrl ( "/admin/delcoll?xml=1&delcoll=qatest123" ) )
return false;
}
//
// add the 'qatest123' collection
//
//static bool s_x2 = false;
if ( ! s_flags[1] ) {
s_flags[1] = true;
if ( ! getUrl ( "/admin/addcoll?addcoll=qatest123&xml=1" ,
// checksum of reply expected
238170006 ) )
return false;
}
// turn off images thumbnails
if ( ! s_flags[24] ) {
s_flags[24] = true;
if ( ! getUrl ( "/admin/spider?c=qatest123&mit=0",
// checksum of reply expected
238170006 ) )
return false;
}
// add the 50 urls
if ( ! s_flags[3] ) {
s_flags[3] = true;
SafeBuf sb;
sb.safePrintf("&c=qatest123"
"&format=json"
"&strip=1"
"&spiderlinks=0"
"&urls="//www.walmart.com+ibm.com"
);
sb.urlEncode ( s_ubuf4 );
// . now a list of websites we want to spider
// . the space is already encoded as +
if ( ! getUrl ( "/admin/addurl",0,sb.getBufStart()) )
return false;
}
//
// wait for spidering to stop
//
checkagain:
// wait until spider finishes. check the spider status page
// in json to see when completed
//static bool s_k1 = false;
if ( ! s_flags[5] ) {
// wait 5 seconds, call sleep timer... then call qatest()
//usleep(5000000); // 5 seconds
wait(3.0);
s_flags[5] = true;
return false;
}
if ( ! s_flags[15] ) {
s_flags[15] = true;
if ( ! getUrl ( "/admin/status?format=json&c=qatest123",0) )
return false;
}
//static bool s_k2 = false;
if ( ! s_flags[6] ) {
// ensure spiders are done.
// "Nothing currently available to spider"
if ( s_content&&!strstr(s_content,"Nothing currently avail")){
s_flags[5] = false;
s_flags[15] = false;
goto checkagain;
}
s_flags[6] = true;
}
if ( ! s_flags[7] ) {
s_flags[7] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&"
"q=type%3Ajson+meta.authors%3Appk",
-1310551262 ) )
return false;
}
if ( ! s_flags[8] ) {
s_flags[8] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=xml&n=100&"
"q=type%3Ajson",
-1310551262 ) )
return false;
}
if ( ! s_flags[9] ) {
s_flags[9] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=json&"
"q=gbfacetstr%3Ameta.authors",
-1310551262 ) )
return false;
}
if ( ! s_flags[10] ) {
s_flags[10] = true;
// this has > 50 values for the facet field hash
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=json&"
"q=gbfacetstr%3Astrings.key",
-1310551262 ) )
return false;
}
// other query tests...
if ( ! s_flags[12] ) {
s_flags[12] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=json&"
"q=inurl2%3Aquirksmode.org%2Fm%2F",
-1310551262 ) )
return false;
}
if ( ! s_flags[13] ) {
s_flags[13] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=json&"
"q=site%3Aquirksmode.org",
-1310551262 ) )
return false;
}
// test gbfieldmatch:field:"quoted value" query to ensure it converts
// the quoted value into the right int32
if ( ! s_flags[14] ) {
s_flags[14] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=json&"
"q=gbfieldmatch%3Astrings.key"
"%3Ainvestigate-tweet",
-1310551262 ) )
return false;
}
if ( ! s_flags[15] ) {
s_flags[15] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=json&"
"q=gbfieldmatch%3Astrings.key"
"%3A\"Maemo+Browser\"",
-1310551262 ) )
return false;
}
if ( ! s_flags[16] ) {
s_flags[16] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=json&"
"q=gbfieldmatch%3Astrings.key"
"%3A\"Google+Wireless+Transcoder\"",
-1310551262 ) )
return false;
}
// this should have no results, not capitalized
if ( ! s_flags[17] ) {
s_flags[17] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=json&"
"q=gbfieldmatch%3Astrings.key%3A\"samsung\"",
-1310551262 ) )
return false;
}
if ( ! s_flags[18] ) {
s_flags[18] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=json&"
"q=gbfieldmatch%3Astrings.key%3ASamsung",
-1310551262 ) )
return false;
}
if ( ! s_flags[18] ) {
s_flags[18] = true;
if ( ! getUrl ( "/search?c=qatest123&qa=1&format=json&"
"q=gbfieldmatch%3Astrings.key%3A\"Samsung\"",
-1310551262 ) )
return false;
}
//static bool s_fee2 = false;
if ( ! s_flags[20] ) {
s_flags[20] = true;
log("qa: SUCCESSFULLY COMPLETED "
"QA JSON TEST");
return true;
}
return true;
}
2014-07-30 06:51:41 +04:00
2014-07-26 19:12:42 +04:00
/*
2014-07-14 18:13:55 +04:00
bool qaspider ( ) {
if ( ! s_callback ) s_callback = qaspider;
// do first qa test for spider
2014-07-14 23:44:32 +04:00
// returns true when done, false when blocked
2014-07-15 21:06:33 +04:00
if ( ! qaspider1() ) return false;
2014-07-14 18:13:55 +04:00
// do second qa test for spider
2014-07-14 23:44:32 +04:00
// returns true when done, false when blocked
if ( ! qaspider2() ) return false;
2014-07-14 18:13:55 +04:00
return true;
}
2014-07-26 19:12:42 +04:00
*/
2014-07-26 04:39:29 +04:00
static QATest s_qatests[] = {
2014-07-26 19:12:42 +04:00
{qainject1,
"injectTest1",
2014-07-29 06:15:31 +04:00
"Test injection api. Test injection of multiple urls with content. "
"Test deletion of urls via inject api."},
2014-07-26 19:12:42 +04:00
{qainject2,
"injectTest2",
2014-07-29 06:15:31 +04:00
"Test injection api. Test delimeter-based injection of single file. "
"test tml ns smxcpl sw showimages sc search parms."},
2014-07-26 04:39:29 +04:00
{qaspider1,
"spiderSitePagesTest",
2014-07-29 06:15:31 +04:00
"Test spidering walmart.com and ibm.com using sitepages quota. "
"Test facets."},
2014-07-26 04:39:29 +04:00
{qaspider2,
"spiderHopCountTest",
2014-07-30 06:51:41 +04:00
"Test spidering ibm.com using hopcount limit."},
{qascrape,
"queryScrapeTest",
"Scrape and inject results from google and bing."},
{qajson,
"jsonTest",
"Add Url some JSON pages and test json-ish queries. Test facets over "
"json docs."},
{qaimport,
"importDataTest",
"Test data import functionality."}
2014-07-26 04:39:29 +04:00
};
2014-07-26 19:12:42 +04:00
void resetFlags() {
long n = sizeof(s_qatests)/sizeof(QATest);
for ( long i = 0 ; i < n ; i++ ) {
QATest *qt = &s_qatests[i];
memset(qt->m_flags,0,4*MAXFLAGS);
2014-07-26 19:12:42 +04:00
}
}
// . run a series of tests to ensure that gb is functioning properly
// . uses the ./qa subdirectory to hold archive pages, ips, spider dates to
// ensure consistency between tests for exact replays
bool qatest ( ) {
2014-07-28 22:13:02 +04:00
if ( s_registered ) {
g_loop.unregisterSleepCallback(NULL,qatestWrapper);
s_registered = false;
}
2014-07-09 07:33:13 +04:00
if ( ! s_callback ) s_callback = qatest;
2014-07-27 07:05:05 +04:00
if ( ! g_qaSock ) return true;
2014-07-28 22:13:02 +04:00
2014-07-14 23:44:32 +04:00
// returns true when done, false when blocked
2014-07-26 04:39:29 +04:00
//if ( ! qainject ( ) ) return false;
2014-07-14 23:44:32 +04:00
// returns true when done, false when blocked
2014-07-26 04:39:29 +04:00
//if ( ! qaspider ( ) ) return false;
long n = sizeof(s_qatests)/sizeof(QATest);
for ( long i = 0 ; i < n ; i++ ) {
QATest *qt = &s_qatests[i];
2014-07-26 19:12:42 +04:00
if ( ! qt->m_doTest ) continue;
2014-07-27 07:05:05 +04:00
// store that
s_qt = qt;
2014-07-26 19:12:42 +04:00
// point to flags
s_flags = qt->m_flags;
2014-07-26 04:39:29 +04:00
// call the qatest
2014-07-26 19:12:42 +04:00
if ( ! qt->m_func() ) return false;
2014-07-26 04:39:29 +04:00
}
2014-07-09 07:33:13 +04:00
2014-07-27 05:43:11 +04:00
// save this
2014-07-29 06:15:31 +04:00
saveHashTable();
// do not reset since we don't reload it above!
//s_ht.reset();
2014-07-27 05:43:11 +04:00
2014-07-28 22:13:02 +04:00
//if ( g_numErrors )
// g_qaOutput.safePrintf("<input type=submit value=submit><br>");
2014-07-27 05:43:11 +04:00
g_qaOutput.safePrintf("<br>DONE RUNNING QA TESTS<br>");
2014-07-28 22:13:02 +04:00
2014-07-26 17:59:05 +04:00
// . print the output
// . the result of each test is stored in the g_qaOutput safebuf
g_httpServer.sendDynamicPage(g_qaSock,
g_qaOutput.getBufStart(),
g_qaOutput.length(),
-1/*cachetime*/);
g_qaOutput.purge();
2014-07-27 05:43:11 +04:00
g_qaSock = NULL;
2014-07-09 07:33:13 +04:00
return true;
}
2014-07-26 04:39:29 +04:00
#include "Parms.h"
#include "Pages.h"
bool sendPageQA ( TcpSocket *sock , HttpRequest *hr ) {
char pbuf[32768];
SafeBuf sb(pbuf, 32768);
//char format = hr->getReplyFormat();
// set this. also sets gr->m_hr
GigablastRequest gr;
// this will fill in GigablastRequest so all the parms we need are set
g_parms.setGigablastRequest ( sock , hr , &gr );
2014-07-26 17:59:05 +04:00
2014-07-28 22:13:02 +04:00
//
// . handle a request to update the crc for this test
// . test id identified by "ajaxUrlHash" which is the hash of the test's url
// and the test name, QATest::m_testName
long ajax = hr->getLong("ajax",0);
2014-07-29 06:15:31 +04:00
unsigned long ajaxUrlHash ;
ajaxUrlHash = (unsigned long long)hr->getLongLong("uh",0LL);
unsigned long ajaxCrc ;
ajaxCrc = (unsigned long long)hr->getLongLong("crc",0LL);
2014-07-28 22:13:02 +04:00
if ( ajax ) {
2014-07-29 06:15:31 +04:00
// make sure it is initialized
if ( s_ht.m_ks ) {
// overwrite current value with provided one because
// the user click on an override checkbox to update
// the crc
s_ht.addKey ( &ajaxUrlHash , &ajaxCrc );
saveHashTable();
}
2014-07-28 22:13:02 +04:00
// send back the urlhash so the checkbox can turn the
// bg color of the "diff" gray
SafeBuf sb3;
sb3.safePrintf("%lu",ajaxUrlHash);
g_httpServer.sendDynamicPage(sock,
sb3.getBufStart(),
sb3.length(),
-1/*cachetime*/);
return true;
}
2014-07-26 17:59:05 +04:00
// if they hit the submit button, begin the tests
long submit = hr->hasField("action");
2014-07-26 19:12:42 +04:00
long n = sizeof(s_qatests)/sizeof(QATest);
if ( submit && g_qaInProgress ) {
g_errno = EINPROGRESS;
g_httpServer.sendErrorReply(sock,g_errno,mstrerror(g_errno));
return true;
}
// set m_doTest
for ( long i = 0 ; submit && i < n ; i++ ) {
QATest *qt = &s_qatests[i];
char tmp[10];
sprintf(tmp,"test%li",i);
qt->m_doTest = hr->getLong(tmp,0);
}
2014-07-26 17:59:05 +04:00
if ( submit ) {
2014-07-26 19:12:42 +04:00
// reset all the static thingies
resetFlags();
// save socket
2014-07-26 17:59:05 +04:00
g_qaSock = sock;
2014-07-28 22:13:02 +04:00
g_numErrors = 0;
g_qaOutput.reset();
g_qaOutput.safePrintf("<html><body>"
"<title>QA Test Results</title>\n");
g_qaOutput.safePrintf("<SCRIPT LANGUAGE=\"javascript\">\n"
// update s_ht with the new crc for this test
"function submitchanges(urlhash,crc) "
"{\n "
"var client=new XMLHttpRequest();\n"
"client.onreadystatechange=gotsubmitreplyhandler;"
"var "
"u='/admin/qa?ajax=1&uh='+urlhash+'&crc='+crc;\n"
"client.open('GET',u);\n"
"client.send();\n"
2014-07-29 06:15:31 +04:00
// use that to fix background to gray
"var w=document.getElementById(urlhash);\n"
// set background color
"w.style.backgroundColor = '0xe0e0e0';\n"
2014-07-28 22:13:02 +04:00
// gear spinning after checkbox
"}\n\n "
// call this when we got the reply that the
// checkbox went through
"function gotsubmitreplyhandler() {\n"
// return if reply is not fully ready
"if(this.readyState != 4 )return;\n"
// if error or empty reply then do nothing
"if(!this.responseText)return;\n"
// response text is the urlhash32, unsigned long
"var id=this.responseText;\n"
// use that to fix background to gray
"var w=document.getElementById(id);\n"
// set background color
"w.style.backgroundColor = '0xe0e0e0';\n"
"}\n\n"
"</SCRIPT> ");
2014-07-26 19:12:42 +04:00
// and run the qa test loop
2014-07-26 17:59:05 +04:00
if ( ! qatest( ) ) return false;
// what happened?
log("qa: qatest completed without blocking");
2014-07-26 04:39:29 +04:00
}
// show tests, all checked by default, to perform
g_pages.printAdminTop ( &sb , sock , hr );
2014-07-28 22:13:02 +04:00
sb.safePrintf("<SCRIPT LANGUAGE=\"javascript\">\n"
"function checkAll(name, num)\n "
2014-07-26 04:39:29 +04:00
"{ "
2014-07-28 22:13:02 +04:00
" for (var i = 0; i < num; i++) {\n"
" var e = document.getElementById(name + i);\n"
2014-07-26 04:39:29 +04:00
//"alert(name+i);"
2014-07-28 22:13:02 +04:00
" e.checked = !e.checked ;\n "
" }\n"
"}\n\n "
2014-07-26 04:39:29 +04:00
"</SCRIPT> ");
2014-07-28 22:13:02 +04:00
2014-07-26 04:39:29 +04:00
//sb.safePrintf("<form name=\"fo\">");
sb.safePrintf("\n<table %s>\n",TABLE_STYLE);
sb.safePrintf("<tr class=hdrow><td colspan=2>"
"<center><b>QA Tests</b></center>"
"</td></tr>");
// header row
sb.safePrintf("<tr><td><b>Do Test?</b> <a style=cursor:hand;"
"cursor:pointer; "
2014-07-26 17:59:05 +04:00
"onclick=\"checkAll('test', %li);\">(toggle)</a>",n);
sb.safePrintf("</td><td><b>Test Name</b></td></tr>\n");
2014-07-26 04:39:29 +04:00
// . we keep the ptr to each test in an array
// . print out each qa function
for ( long i = 0 ; i < n ; i++ ) {
QATest *qt = &s_qatests[i];
char *bg;
if ( i % 2 == 0 ) bg = LIGHT_BLUE;
else bg = DARK_BLUE;
sb.safePrintf("<tr bgcolor=#%s>"
2014-07-26 17:59:05 +04:00
"<td><input type=checkbox value=1 name=test%li "
"id=test%li></td>"
2014-07-26 17:59:05 +04:00
"<td>%s"
"<br>"
"<font color=gray size=-1>%s</font>"
"</td>"
2014-07-26 04:39:29 +04:00
"</tr>\n"
, bg
, i
, i
, qt->m_testName
2014-07-26 17:59:05 +04:00
, qt->m_testDesc
2014-07-26 04:39:29 +04:00
);
}
2014-07-26 17:59:05 +04:00
sb.safePrintf("</table>\n<br>\n");
2014-07-26 04:39:29 +04:00
// "</form>\n");
g_pages.printAdminBottom ( &sb , hr );
g_httpServer.sendDynamicPage(sock,
sb.getBufStart(),
sb.length(),
-1/*cachetime*/);
return true;
}