Esempio n. 1
0
 def testIsTimeToWorkFirst(self):
     # test the first run
     w = Worker()
     self.mox.ReplayAll()
     
     # first and not in worktime
     t = time.gmtime(time.mktime((2012, 10, 1, 15, 26,40,0,0,0)))
     w.last_work_min = None
     istime = False
     while not istime:
         now = time.localtime()
         istime = w.is_timeto_work()
         if not istime:
             ret = w.get_leaving_time()
             sys.stdout.write("\r%02d:%02d:%02d waitting %d seconds for the test of IsTimeToWork  \r" % 
                             (now.tm_hour, now.tm_min, now.tm_sec, ret))
             assert ret == 60 - now.tm_sec
             sys.stdout.flush()
             time.sleep(1)
     print
     
     assert now.tm_sec >=0 and now.tm_sec <= 5
     assert istime == True
     assert not w.last_work_min is None
     
     self.mox.VerifyAll()
     print "update_time test \t[\033[1;33mOK\033[0m]"
     print "is_timeto_work test \t[\033[1;33mOK\033[0m]"
     print "get_leaving_time test \t[\033[1;33mOK\033[0m]"
Esempio n. 2
0
 def testSend(self):
     self.mox.ReplayAll()
     w = Worker(context = ZmqContextMox())
     msg = [1, json.dumps(["1", {86:2012}])]
     w.send(msg)
     self.mox.VerifyAll()
     print "send test \t[\033[1;33mOK\033[0m]"
Esempio n. 3
0
 def testPlugin(self):
     w = Worker()
     w.register_plugin(PluginTrafficAccountingInfoMox)
     w.register_plugin(PluginAgentInfo)
     assert len(w.plugins) == 2
     w.clear_plugin()
     assert len(w.plugins) == 0
     print "Plugin test \t[\033[1;33mOK\033[0m]"
Esempio n. 4
0
 def testInfoPush(self):
     self.mox.ReplayAll()
     w = Worker(context = ZmqContextMox())
     w.register_plugin(PluginTrafficAccountingInfoMox)
     w.register_plugin(PluginAgentInfo)
     w.info_push()
     self.mox.VerifyAll()
     print "info_push test \t[\033[1;33mOK\033[0m]"
Esempio n. 5
0
 def test_istime_to_work(self):
     w = Worker(None)
     
     for _ in range(135):
         time.sleep(w.working_rate)
         now = time.localtime()
         istime = w.is_timeto_work()
         if not istime:
             ret = w.get_leaving_time()
             sys.stdout.write(("\r%02d:%02d:%02d waitting %d seconds for work(last=%d,rate=%d,istime=%s)" % 
                             (now.tm_hour, now.tm_min, now.tm_sec
                             , ret
                             , w.last_work_min
                             , w.working_rate
                             , istime)))
             sys.stdout.flush()
             continue
         print
         sys.stdout.write('%02d:%02d:%02d start fake working.' % 
                         (now[3], now[4], now[5]))
         for __ in range(random.randint(0,60)):
             sys.stdout.write('.')
             sys.stdout.flush()
             time.sleep(1)
         now = time.localtime()
         print '\n%02d:%02d:%02d working success finished.' % \
               (now[3], now[4], now[5])
         w.update_time()
Esempio n. 6
0
 def testWorkerID(self):
     w = Worker(worker_id = 'TestID')
     assert(w.worker_id == 'TestID')
     print "worker_id test \t[\033[1;33mOK\033[0m]"