Re: Emulating AJAX polling requests
"Heintz, Timothy J CTR (US)" <theintz-RD6IL/yZvvVWk0Htik3J/[email protected]>
| Newsgroups | gmane.comp.java.grinder.user |
|---|---|
| Message-ID | <[email protected]> |
Just successfully ran a test on this concept and it worked
beautifully!
The test script follows:
from net.grinder.script import Grinder
from net.grinder.script import Test
grinder = Grinder.grinder
class TestRunner:
def __init__(self):
self.threadName = 'main'
def threadDelay(self, msg):
grinder.sleep(5000)
print msg
def __call__(self):
sub = TestRunnerThread()
grinder.startWorkerThread(sub)
self.threadDelay('Main Thread with sub running')
sub.runIt = False
self.threadDelay('Main Thread with sub stopped')
class TestRunnerThread:
def __init__(self):
self.threadName = 'sub'
self.runIt =True
def threadDelaySub(self, msg):
grinder.sleep(1000)
print msg
def __call__(self):
while self.runIt:
self.threadDelaySub('Sub thread is running')
def instrumentMethod(test, method_name, c=TestRunner):
"""Instrument a method with the given Test."""
unadorned = getattr(c, method_name)
import new
method = new.instancemethod(test.wrap(unadorned), None,
c)
setattr(c, method_name, method)
def instrumentMethodThread(test, method_name,
c=TestRunnerThread):
"""Instrument a method with the given Test."""
unadorned = getattr(c, method_name)
import new
method = new.instancemethod(test.wrap(unadorned), None,
c)
setattr(c, method_name, method)
instrumentMethod(Test(100, 'Thead Delay'), 'threadDelay')
instrumentMethodThread(Test(200, 'Rhread Delay Sub'),
'threadDelaySub')
Thanks much
On 11/15/2013 11:07 AM, Marc Holden
wrote:
That is correct, however, the we have implemented
it is to create a new TestRunner class with __call__ method
being implemented, just as you normally do. In the constructor
(__init__) we pass in all the data the class will worker will
need. This includes cookies, parameters, and the instrumented
Request object. We also have an isDone boolean included in the
class that we can monitor changes but I'd imagine you could use
a barrier for this. Once the request comes back, we set the
isDone value to true.
1. TestRunner class is instantiated with all the values
it needs.
2. We pass the class to the grinder.startWorker
3. Monitor isDone to determine when the request is
finished (if we even care). Most of the time we do care
because the response contains data we need for the next
request...
With this the test runners don't need to 'talk' to each
other as long as the data is exposed on the objects but you
need to know a lot of data upfront. I like to approach the
xhr TestRunners almost like a Java Bean with the added ability
of making the HTTP Request.
-Marc
On Fri, Nov 15, 2013 at 9:17 AM,
Heintz, Timothy J CTR (US) <theintz-RD6IL/yZvvVWk0Htik3J/[email protected] > wrote:
Thanks,
I was thinking that the solution was something like this.
However, I still have questions concerning how this
handled.
The docs state that you can provide method that I assume
will act as the main TestRunner method for the new
thread. Is this correct?
I am still uncertain how the two TestRunner threads talk
to each other.
Also can the method provided to the startWorker call be an
instrumented method so the the response statistics are
reported?
Thanks in advance for you help
Tim
On 11/13/2013 10:48 PM, Marc Holden wrote:
You can put the xhr request in its own TestRunner
and call grinder.startWorker to fire off the
request. If you need to know when the worker is
done, add a variable which you poll periodically.
Hope this helps...
-Marc
On Nov 13, 2013 4:24 PM,
"Heintz, Timothy J CTR (US)" <theintz-RD6IL/yZvvVWk0Htik3J/[email protected] >
wrote:
The
problem is not in recording the request, but
in executing it a separate thread.
Grinder appears to not allow calling an
instrumented method from any thread other than
the main "worker" thread that invoked by the
TestRunner.
Tim
On 11/13/2013 12:31 PM, Ravi Joshi wrote:
If JavaScript is sending any
HTTP request, then you can record this
scenario using TCP-Proxy. Once you
have the recorded script, you can do
little modification as per the
requirement.
-Ravi Joshi
On Wednesday, 13 November 2013
12:39 AM, "Heintz, Timothy J CTR
(US)" <theintz-RD6IL/yZvvVWk0Htik3J/[email protected]>
wrote:
Hi,
We have an web application in
which JavaScript periodically
polls the
server.
To emulate this, I created a
Python Thread that periodically
executes a
callback to an instrumented
TestRunner method, the executes
the poling
request.
This approach generated the
following error: "Only Worker
Threads can
invoke tests". Apparently Grinder
does not allow Python-created
threads to execute instrumented
methods.
Is there another way this task can
be accomplished?
Thanks,
Tim
------------------------------------------------------------------------------
DreamFactory - Open Source REST
& JSON Services for HTML5
& Native Apps
OAuth, Users, Roles, SQL, NoSQL,
BLOB Storage and External API
Access
Free app hosting. Or install the
open source package on any LAMP
server.
Sign up and see examples for
AngularJS, jQuery, Sencha Touch
and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use
------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON
Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage
and External API Access
Free app hosting. Or install the open source
package on any LAMP server.
Sign up and see examples for AngularJS, jQuery,
Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use
------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use
------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for
HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External
API Access
Free app hosting. Or install the open source package on any
LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch
and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use
------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use
------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use