""" Run
"""
import sys
import time
import logging
log = logging.getLogger(__file__)

from ott.utils.cache_base import CacheBase
from .. import tests_to_urls


class StressTests(CacheBase):
    """ stress test OTP
    """
    graphs = None

    def __init__(self):
        super(StressTests, self).__init__('otp')

        parser = tests_to_urls.get_args_parser()
        parser.add_argument('--threads',  '-t', default=10, help="number of threads")
        parser.add_argument('--number',   '-n', type=int, help="number of iterations")
        parser.add_argument('--duration', '-d', type=int, help="length of time (seconds) to run (as opposed to --number of iterations)")
        args = parser.parse_args()

        self.args = args
        self.url_hash = tests_to_urls.run(args)
        if args.number:
            self.iterations_stress_test(args.number)
        elif args.duration:
            self.duration_stress_test(args.duration)

    def duration_stress_test(self, duration):
        for i in duration:
            print "x"

    def iteration_stress_test(self, num_iterations):
        pass

    def printer(self, force=False):
        if force or self.args.printer or (not self.args.number and not self.args.duration):
            tests_to_urls.printer(self.args, self.this_module_dir, self.url_hash)

    @classmethod
    def run(cls):
        success = True
        st = StressTests()
        st.printer()
        return success


def main():
    StressTests.run()

if __name__ == '__main__':
    main()

@@ -28,16 +28,32 @@
 rt time%0A
+import datetime%0A
 import l
@@ -985,32 +985,34 @@
 t(self, duration
+=5
 ):%0A        for i
@@ -1010,26 +1010,194 @@
     
-for i in duration:
+now = datetime.datetime.now()%0A        end = now + datetime.timedelta(seconds=duration)%0A        i = 0%0A        while now %3C end:%0A            now = datetime.datetime.now()%0A            i += 1
 %0A   
@@ -1215,11 +1215,9 @@
 int 
-%22x%22
+i
 %0A%0A  
@@ -1227,24 +1227,25 @@
 ef iteration
+s
 _stress_test
@@ -1280,12 +1280,59 @@
     
-pass
+for i in range(num_iterations):%0A            print i
 %0A%0A  

add the stress run routines