Permalink
Browse files

added test.py

  • Loading branch information...
1 parent 218e013 commit 744f56e016ce268ac6f50384afb47084dd5b7f88 @jaivikram jaivikram committed with slact Jan 7, 2010
Showing with 34 additions and 0 deletions.
  1. +34 −0 tests/test.py
View
@@ -0,0 +1,34 @@
+import urllib2
+import simplejson
+import random
+import time
+from threading import Thread
+import threadpool
+import os
+PUBLISHER_URL = 'http://localhost:8080/publish/?channel=232'
+SUBSCRIBER_URL = 'http://localhost:8080/activity/?channel=232'
+import logging
+logging.basicConfig(level = logging.DEBUG)
+log = logging.getLogger('test.py')
+
+def publish():
+ res = urllib2.urlopen(PUBLISHER_URL, \
+ data = simplejson.dumps(\
+ {'message': 'hello world %d' % random.randint(1, 100)}))
+ return
+
+def subscribe(dummy):
+ res = urllib2.urlopen(SUBSCRIBER_URL)
+ log.info('pid::'+str(os.getpid()))
+ log.info('msg:: '+res.read()+'\n')
+
+
+if __name__ == '__main__':
+ pool = threadpool.ThreadPool(2)
+ requests = threadpool.makeRequests(subscribe, [1]*20)
+ while True:
+ t = Thread(target = publish)
+ t.run()
+ [pool.putRequest(request) for request in requests]
+ pool.wait()
+ #time.sleep(random.randint(3, 4))

0 comments on commit 744f56e

Please sign in to comment.