123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- import os
- import sys
- import threading
- import time
- PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
- sys.path.insert(0, PROJECT_ROOT)
- os.environ.update({"DJANGO_SETTINGS_MODULE": "configs.testing"})
- import django
- django.setup()
- from apps.web.core.helpers import ActionDeviceBuilder
- from apps.web.device.models import Device
- class Tester(threading.Thread):
- def __init__(self,sleepTime, runTimes,logicalCode,func,**args):
- super(Tester, self).__init__()
- dev = Device.get_dev_by_l(logicalCode)
- self._smartBox = ActionDeviceBuilder.create_action_device(dev)
- self._func = func
- self._args = args
- self._runTimes = runTimes
- self._sleepTime = sleepTime
-
- def run(self):
- count = 0
- while count < self._runTimes:
- count += 1
- try:
- result = eval('self._smartBox.%s(**self._args)' % self._func)
- # result = self._smartBox.get_port_status_from_dev()
- print result
- if self._sleepTime:
- time.sleep(self._sleepTime)
- except Exception,e:
- if u'充电桩正在忙' in e.result.get('description'):
- print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!error = %s,func=%s' % (e,self._func))
- logicalCode = '865650042312401'
- ii = 0
- # for ii in range(10):
- # Tester(0,100000,logicalCode,'get_port_status_from_dev').start()
- # #
- # ii = 0
- # for ii in range(10):
- # Tester(0,100000,logicalCode,'get_port_info',line=ii%10).start()
- # #
- # #
- # #
- # ii = 0
- # for ii in range(2):
- # Tester(0,100000,logicalCode,'get_dev_consume_count').start()
- # #
- # ii = 0
- # for ii in range(2):
- # Tester(0,100000,logicalCode,'get_dev_setting').start()
- ii = 0
- for ii in range(9):
- Tester(1,1000,logicalCode,'start_device',package={'time':3,'unit':u'分钟','coins':1,'price':1},openId='aaaaaaaaaaaaaa',attachParas = {'chargeIndex':ii}).start()
- # ii = 0
- # for ii in range(10):
- # Tester(200,100000,logicalCode,'stop_charging_port',port = ii).start()
- print 'finished'
|