Thread: AW: [Httpunit-develop] Running tests in different threads causes errors in test script
Brought to you by:
russgold
From: EdA-qa Mort-ora-y <mor...@ec...> - 2005-10-28 07:24:24
|
Have you checked your webserver logs? Perhaps your simple test just = happens to overload your server and you get an incorrect response. Try dumping the value of the WebResponse after each response and verify = that it is what you expect in all cases. > -----Urspr=FCngliche Nachricht----- > Von: htt...@li... > [mailto:htt...@li...]Im Auftrag von > Jason > Gesendet: Donnerstag, 27. Oktober 2005 23:35 > An: htt...@li... > Betreff: [Httpunit-develop] Running tests in different threads causes > errors in test script >=20 >=20 > I am having problems when running a test script that uses=20 > multiple threads in the same JVM. When > I run the example that follows, I get NullPointerException,=20 > IllegalUnnamedSubmitButtonException, > NoSuchParameterException. It appears that the threads are=20 > affecting the state of other threads in > some way. >=20 > I can, however, run the script with only one thread, and it=20 > never fails. >=20 > In addition, I can run the script many times in different JVM=20 > instances on the same machine > (running it multiple times in Eclipse, to be exact), without=20 > any problems. >=20 > Here is a sanitized example of the type of script I am running. >=20 > import java.io.IOException; > import org.xml.sax.SAXException; > import com.meterware.httpunit.*; > =20 > public class Demo implements Runnable { > private static String URL =3D=20 > "http://somehost.com:8080/app/startpage.jsp"; > private WebForm form; > private WebLink link; > private WebRequest request; > private WebResponse response; > private WebConversation wc; > =20 > public static void main(String[] params) { > new Thread(new Demo()).start(); > new Thread(new Demo()).start(); // works if i=20 > comment this line out > new Thread(new Demo()).start(); // works if i=20 > comment this line out > new Thread(new Demo()).start(); // works if i=20 > comment this line out > } > =20 > public void doScript() throws SAXException, IOException { > request =3D new GetMethodWebRequest(URL); > response =3D wc.getResponse(request); > link =3D response.getLinkWith("New Task"); > response =3D link.click(); > form =3D response.getFormWithName("firstform"); > form.setParameter("thing1", "value1"); > form.setParameter("thing2", "value2"); > form.setParameter("thing3", "value3"); > response =3D form.submit(form.getSubmitButton("nextPage")); > form =3D response.getFromWithName("nextForm"); > form.setParameter("thing1", "value1"); > form.setParameter("thing2", "value2"); > form.setParameter("thing3", "value3"); > form =3D response.getFormWithName("anotherform"); > form.setParameter("thing1", "value1"); > response =3D form.submit(form.getSubmitButton("Finish")); > // ETC ETC ETC > } > =20 > public void run() { > try { > HttpUnitOptions.setScriptingEnabled(false); > wc =3D new WebConversation(); > wc.setAuthorization("username", "password"); > System.out.println("Thread started"); > for (int x =3D 0; x < 50; x++) { > doScript(); > } > System.out.println("Thread ended"); > } catch (Exception e) { > e.printStackTrace(System.out); > } > } > } >=20 > If i comment the noted lines out, it runs fine. And if after=20 > I comment the lines out, I run it > multiple times in separate virtual machines, it works fine. =20 > But if I leave the lines uncommented, > it has problems running the scripts in multiple threads in=20 > the same VM. >=20 > If anyone can tell what I am doing wrong, or if there is some=20 > bug or workaround, I would greatly > appreciate it. As you can see, the variables are all=20 > non-static so there is no sharing between > instances, and I have created a WebConversation per Thread. >=20 > Thanks, > Jason >=20 >=20 >=20 > =09 > __________________________________=20 > Yahoo! FareChase: Search multiple travel sites in one click. > http://farechase.yahoo.com >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by the JBoss Inc. > Get Certified Today * Register for a JBoss Training Course > Free Certification Exam for All Training Attendees Through End of 2005 > Visit http://www.jboss.com/services/certification for more information > _______________________________________________ > Httpunit-develop mailing list > Htt...@li... > https://lists.sourceforge.net/lists/listinfo/httpunit-develop >=20 |
From: Jason <ha...@ya...> - 2005-10-28 17:39:28
|
Well, the webserver logs dont show much more than the activity of the script until it fails. Even so, like I said, the script works fine if I execute each script with one thread in a different JVM. For example, if I open a bunch of command windows and run the java command in each window. I will just probably use a different testing framework than httpunit, however, since this is a serious bug in my opinion. WebConversations should be independent of eachother and threadsafe, I should not have to run multiple JVMs (which takes tons of memory, etc, and is hard to track overall statistics between the instances). --- EdA-qa Mort-ora-y <mor...@ec...> wrote: > Have you checked your webserver logs? Perhaps your simple test just happens to overload your > server and you get an incorrect response. > > Try dumping the value of the WebResponse after each response and verify that it is what you > expect in all cases. > > > > -----Ursprüngliche Nachricht----- > > Von: htt...@li... > > [mailto:htt...@li...]Im Auftrag von > > Jason > > Gesendet: Donnerstag, 27. Oktober 2005 23:35 > > An: htt...@li... > > Betreff: [Httpunit-develop] Running tests in different threads causes > > errors in test script > > > > > > I am having problems when running a test script that uses > > multiple threads in the same JVM. When > > I run the example that follows, I get NullPointerException, > > IllegalUnnamedSubmitButtonException, > > NoSuchParameterException. It appears that the threads are > > affecting the state of other threads in > > some way. > > > > I can, however, run the script with only one thread, and it > > never fails. > > > > In addition, I can run the script many times in different JVM > > instances on the same machine > > (running it multiple times in Eclipse, to be exact), without > > any problems. > > > > Here is a sanitized example of the type of script I am running. > > > > import java.io.IOException; > > import org.xml.sax.SAXException; > > import com.meterware.httpunit.*; > > > > public class Demo implements Runnable { > > private static String URL = > > "http://somehost.com:8080/app/startpage.jsp"; > > private WebForm form; > > private WebLink link; > > private WebRequest request; > > private WebResponse response; > > private WebConversation wc; > > > > public static void main(String[] params) { > > new Thread(new Demo()).start(); > > new Thread(new Demo()).start(); // works if i > > comment this line out > > new Thread(new Demo()).start(); // works if i > > comment this line out > > new Thread(new Demo()).start(); // works if i > > comment this line out > > } > > > > public void doScript() throws SAXException, IOException { > > request = new GetMethodWebRequest(URL); > > response = wc.getResponse(request); > > link = response.getLinkWith("New Task"); > > response = link.click(); > > form = response.getFormWithName("firstform"); > > form.setParameter("thing1", "value1"); > > form.setParameter("thing2", "value2"); > > form.setParameter("thing3", "value3"); > > response = form.submit(form.getSubmitButton("nextPage")); > > form = response.getFromWithName("nextForm"); > > form.setParameter("thing1", "value1"); > > form.setParameter("thing2", "value2"); > > form.setParameter("thing3", "value3"); > > form = response.getFormWithName("anotherform"); > > form.setParameter("thing1", "value1"); > > response = form.submit(form.getSubmitButton("Finish")); > > // ETC ETC ETC > > } > > > > public void run() { > > try { > > HttpUnitOptions.setScriptingEnabled(false); > > wc = new WebConversation(); > > wc.setAuthorization("username", "password"); > > System.out.println("Thread started"); > > for (int x = 0; x < 50; x++) { > > doScript(); > > } > > System.out.println("Thread ended"); > > } catch (Exception e) { > > e.printStackTrace(System.out); > > } > > } > > } > > > > If i comment the noted lines out, it runs fine. And if after > > I comment the lines out, I run it > > multiple times in separate virtual machines, it works fine. > > But if I leave the lines uncommented, > > it has problems running the scripts in multiple threads in > > the same VM. > > > > If anyone can tell what I am doing wrong, or if there is some > > bug or workaround, I would greatly > > appreciate it. As you can see, the variables are all > > non-static so there is no sharing between > > instances, and I have created a WebConversation per Thread. > > > > Thanks, > > Jason > > > > > > > > > > __________________________________ > > Yahoo! FareChase: Search multiple travel sites in one click. > > http://farechase.yahoo.com > > > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by the JBoss Inc. > > Get Certified Today * Register for a JBoss Training Course > > Free Certification Exam for All Training Attendees Through End of 2005 > > Visit http://www.jboss.com/services/certification for more information > > _______________________________________________ > > Httpunit-develop mailing list > > Htt...@li... > > https://lists.sourceforge.net/lists/listinfo/httpunit-develop > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by the JBoss Inc. > Get Certified Today * Register for a JBoss Training Course > Free Certification Exam for All Training Attendees Through End of 2005 > Visit http://www.jboss.com/services/certification for more information > _______________________________________________ > Httpunit-develop mailing list > Htt...@li... > https://lists.sourceforge.net/lists/listinfo/httpunit-develop > __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com |