ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
2.4 KiB

  1. #!/usr/bin/env python
  2. # coding=utf-8
  3. # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
  4. import socket
  5. import time
  6. import traceback
  7. import random
  8. import sys
  9. timeout_time = 5
  10. def test(x):
  11. if not x:
  12. print "Error"
  13. traceback.print_stack()
  14. sys.exit(1)
  15. def make_sock():
  16. s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);
  17. s.connect(('localhost',8080));
  18. s.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1)
  19. return s;
  20. def test_unfinished_out(msg,chunks=[]):
  21. print "Tesing %s with %d chunks" % (msg,len(chunks))
  22. s=make_sock();
  23. if len(msg) > 0 :
  24. s.send(msg)
  25. if len(chunks) > 0:
  26. for chunk in chunks:
  27. time.sleep(1)
  28. s.send(chunk)
  29. start = time.time()
  30. text = s.recv(1)
  31. passed = time.time() - start
  32. test(len(text) == 0)
  33. global timeout_time
  34. test(passed > timeout_time - 2)
  35. test(passed < timeout_time + 2)
  36. def test_unfinished_read(msg,reads,ignore):
  37. print "Tesing %s with %d reads" % (msg,reads)
  38. s=make_sock();
  39. s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF,32768)
  40. read_size = s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)
  41. print "SO_RCVBUF=%d" % read_size
  42. if read_size < 32768:
  43. read_size = 32768
  44. s.send(msg + '\r\n\r\n')
  45. for n in xrange(0,reads):
  46. time.sleep(1)
  47. text = s.recv(read_size)
  48. l = len(text)
  49. test(l > 0)
  50. global timeout_time
  51. time.sleep(timeout_time * 2)
  52. n=0
  53. while 1:
  54. text = s.recv(read_size);
  55. if len(text) > 0:
  56. n = n + len(text)
  57. else:
  58. break
  59. test(n < read_size * 16 or n < 1000000)
  60. write = sys.argv[1] == 'write'
  61. if len(sys.argv) >= 3:
  62. timeout_time = int(sys.argv[2])
  63. if write:
  64. print 'Write to the client timeout'
  65. test_unfinished_read('GET /async/long HTTP/1.0',0,0)
  66. test_unfinished_read('GET /async/long HTTP/1.0',timeout_time + 20,1000)
  67. test_unfinished_read('GET /sync/long HTTP/1.0',0,0)
  68. test_unfinished_read('GET /sync/long HTTP/1.0',timeout_time + 20,1000)
  69. else:
  70. print 'Read from client timeouts'
  71. test_unfinished_out('')
  72. test_unfinished_out('GET /sync/long')
  73. test_unfinished_out('POST /sync/long HTTP/1.0\r\nContent-Length:10000\r\n\r\nbla bla')
  74. test_unfinished_out('POST /sync/long HTTP/1.0\r\nContent-Length:10000\r\n\r\n', ['ss','ss','ss','ss'])
  75. print 'Disconnect the client timeout'
  76. test_unfinished_out('GET /async/goteof HTTP/1.0\r\n\r\n')
  77. time.sleep(1)