Exemple #1
0
 def __init__(self, hub=None):
     """
     .. versionchanged:: 20.5.1
        Add the ``hub`` argument.
     """
     self._block = Semaphore(1, hub)
     self._owner = None
     self._count = 0
Exemple #2
0
 def __init__(self, fobj, environ):
     self.origin = environ.get('HTTP_ORIGIN')
     self.protocol = environ.get('HTTP_SEC_WEBSOCKET_PROTOCOL')
     self.path = environ.get('PATH_INFO')
     self._writelock = Semaphore(1)
     self.fobj = fobj
     self._write = _get_write(fobj)
Exemple #3
0
 def __init__(self, fobj, environ):
     self.origin = environ.get('HTTP_SEC_WEBSOCKET_ORIGIN')
     self.protocol = environ.get('HTTP_SEC_WEBSOCKET_PROTOCOL', 'unknown')
     self.path = environ.get('PATH_INFO')
     self._chunks = bytearray()
     self._first_opcode = None
     self._writelock = Semaphore(1)
     self.fobj = fobj
     self._write = _get_write(fobj)
Exemple #4
0
class RLock(object):

    def __init__(self):
        self._block = Semaphore(1)
        self._owner = None
        self._count = 0

    def __repr__(self):
        return "<%s at 0x%x _block=%s _count=%r _owner=%r)>" % (
            self.__class__.__name__,
            id(self),
            self._block,
            self._count,
            self._owner)

    def acquire(self, blocking=1):
        me = getcurrent()
        if self._owner is me:
            self._count = self._count + 1
            return 1
        rc = self._block.acquire(blocking)
        if rc:
            self._owner = me
            self._count = 1
        return rc

    def __enter__(self):
        return self.acquire()

    def release(self):
        if self._owner is not getcurrent():
            raise RuntimeError("cannot release un-aquired lock")
        self._count = count = self._count - 1
        if not count:
            self._owner = None
            self._block.release()

    def __exit__(self, typ, value, tb):
        self.release()

    # Internal methods used by condition variables

    def _acquire_restore(self, count_owner):
        count, owner = count_owner
        self._block.acquire()
        self._count = count
        self._owner = owner

    def _release_save(self):
        count = self._count
        self._count = 0
        owner = self._owner
        self._owner = None
        self._block.release()
        return (count, owner)

    def _is_owned(self):
        return self._owner is getcurrent()
Exemple #5
0
from locust import HttpUser, task, TaskSet, between, events
import random, time, json
import base64
import sys
import queue
from requests_toolbelt import MultipartEncoder
sys.path.append("F:/myTestFile/TestObject/TongChuangYuanMa")
from yunqianbao.qianMing import GetDataSign
from yunqianbao.publicRequestMethod import PublicRequest
from common.writeAndReadText import WriteAndReadTextFile
from yunqianbao.single.publicData import PublicDataClass
from yunqianbao.single.userMobile import user_mobile
from yunqianbao.pengyou.pengYouClass import PengYouClass
from common.userAgent import UserAgent
from gevent._semaphore import Semaphore
all_locusts_spawned = Semaphore()  #计数器
all_locusts_spawned.acquire()  #计数器为0时阻塞线程 每当调用acquire()时,内置计数器-1


def on_hatch_complete(**kwargs):
    all_locusts_spawned.release()  #内置计数器+1


events.hatch_complete += on_hatch_complete


class YunQianBaoMan(TaskSet):
    def on_start(self):
        self.header = {
            "Connection": "keep-alive",
            "app-type": "android",  #android
Exemple #6
0
 def __init__(self):
     self._block = Semaphore(1)
     self._owner = None
     self._count = 0
Exemple #7
0
 def release(self):
     if self.counter >= self._initial_value:
         raise ValueError("Semaphore released too many times")
     return Semaphore.release(self)
Exemple #8
0
 def __init__(self, value=1):
     Semaphore.__init__(self, value)
     self._initial_value = value
Exemple #9
0
 def __init__(self):
     self._block = Semaphore(1)
     self._owner = None
     self._count = 0
Exemple #10
0
 def release(self):
     if self.counter >= self._initial_value:
         raise ValueError("Semaphore released too many times")
     return Semaphore.release(self)
Exemple #11
0
 def __init__(self, value=1):
     Semaphore.__init__(self, value)
     self._initial_value = value
Exemple #12
0
from bin.Yaml import get_env
from locust import events, TaskSet, task, HttpLocust
from gevent._semaphore import Semaphore

all_locusts_spawned = Semaphore()
all_locusts_spawned.acquire()


def on_hatch_complete(**kwargs):
    all_locusts_spawned.release()


events.hatch_complete += on_hatch_complete
env = get_env()
headers = {
    "User-Agent":
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko)\
                                  Chrome/67.0.3396.99 Safari/537.36",
    "Content-Type": "application/x-www-form-urlencoded",
    # "Connection": "close"
}


class TestTask(TaskSet):
    def on_start(self):
        """ on_start is called when a Locust start before any task is scheduled
            所有压测的task执行之前等待登录完成
        """
        self.console_host = 'https://iam-test.ctcdn.cn'
        self.workspace_id = "10003885"
        self.login()
Exemple #13
0
from locust import HttpUser,task,TaskSet,between,events
import time,json,random,sys,queue
<<<<<<< HEAD
sys.path.append("E:/myTestFile/TestObject/TongChuangYuanMa")
=======
sys.path.append("F:/myTestFile/TestObject/TongChuangYuanMa")
>>>>>>> cab62fe0f6e06f77d99222bd0a09668caebc2748
from Interface.QueryUsers import queryUsers_ykf
from test_script.publicscript.publicRequestMethod import PublicRequest
from yunkufang.ykf_login import UserLogin
from yunkufang.chuangXinShiChang import ChuangXinShiChang
from gevent._semaphore import Semaphore
from yunqianbao.single.userMobile import user_mobile
spawned = Semaphore() #计数器
spawned.acquire() #计数器为0时阻塞线程 每当调用acquire()时,内置计数器-1
def on_hatch_complete(**kwargs):
    spawned.release() #内置计数器+1
    # print(spawned.release())

# events.spawning_complete += on_hatch_complete
# events.hatch_complete += on_hatch_complete

class CXSCLiuCheng(TaskSet):
    def on_start(self):
        self.header = {
            "User-Agent":"Mozilla/5.0 (Linux; U; Android 8.0.0; zh-cn; ALP-TL00 Build/LRX22G) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 YunKuFang/1.3.3",
            "mobile-system":"android8.0.0",
            "app-type":"Android",
            "app-version":"1.3.3",
            "app-version-code":"13",
            "mobile-unid":"866215038845167",
Exemple #14
0
class RLock(object):
    """
    A mutex that can be acquired more than once by the same greenlet.

    A mutex can only be locked by one greenlet at a time. A single greenlet
    can `acquire` the mutex as many times as desired, though. Each call to
    `acquire` must be paired with a matching call to `release`.

    It is an error for a greenlet that has not acquired the mutex
    to release it.

    Instances are context managers.
    """

    __slots__ = (
        '_block',
        '_owner',
        '_count',
        '__weakref__',
    )

    def __init__(self, hub=None):
        """
        .. versionchanged:: 20.5.1
           Add the ``hub`` argument.
        """
        self._block = Semaphore(1, hub)
        self._owner = None
        self._count = 0

    def __repr__(self):
        return "<%s at 0x%x _block=%s _count=%r _owner=%r)>" % (
            self.__class__.__name__, id(self), self._block, self._count,
            self._owner)

    def acquire(self, blocking=True, timeout=None):
        """
        Acquire the mutex, blocking if *blocking* is true, for up to
        *timeout* seconds.

        .. versionchanged:: 1.5a4
           Added the *timeout* parameter.

        :return: A boolean indicating whether the mutex was acquired.
        """
        me = getcurrent()
        if self._owner is me:
            self._count = self._count + 1
            return 1
        rc = self._block.acquire(blocking, timeout)
        if rc:
            self._owner = me
            self._count = 1
        return rc

    def __enter__(self):
        return self.acquire()

    def release(self):
        """
        Release the mutex.

        Only the greenlet that originally acquired the mutex can
        release it.
        """
        if self._owner is not getcurrent():
            raise RuntimeError("cannot release un-acquired lock")
        self._count = count = self._count - 1
        if not count:
            self._owner = None
            self._block.release()

    def __exit__(self, typ, value, tb):
        self.release()

    # Internal methods used by condition variables

    def _acquire_restore(self, count_owner):
        count, owner = count_owner
        self._block.acquire()
        self._count = count
        self._owner = owner

    def _release_save(self):
        count = self._count
        self._count = 0
        owner = self._owner
        self._owner = None
        self._block.release()
        return (count, owner)

    def _is_owned(self):
        return self._owner is getcurrent()
Exemple #15
0
#         print("stop the Usertask!")
#     @task(1)
#     def job1(self):
#         mars_event.fire(verb = 'love', content = 'locust')

#     @task(3)
#     def job2(self):
#         print("In job2")

# class User(Locust):
#     task_set = UserTask
#     min_wait = 1000
#     max_wait = 3000
#     stop_timeout = 10000
'''设置集合点Semaphore'''
all_locusts_spawned = Semaphore()  #信号量,等待全部启动完毕(hatch_complete)后,释放release信号量
all_locusts_spawned.acquire()


def on_hatch_complete(**kwargs):
    all_locusts_spawned.release()


events.hatch_complete += on_hatch_complete


def request_success_hook(request_type, name, response_time, response_length):
    with open("CRRstSucess.txt", 'a+') as f:
        now_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
        msg = "{}  {}  {}  {}  {}  {}\n".format(now_time, "SUCCESS",
                                                request_type, name,