コード例 #1
0
 def sendRequest(self, param1, param2):
     """A method is called for each recorded page."""
     time.sleep(random.randint(70, 110) / 1000.0)
     print param1, param2
     result = self.app.callAdd(param1, param2)
     print "result:", result
     # 注意param1和param2都是int类型,需要转换成str
     if result.find(str(param1) + ' + ' + str(param2)) == -1:
         print 'Failed!'
         info = time.strftime(ISOTIMEFORMAT,
                              time.localtime(time.time())) + ' Test:' + TEST_NAME + ' [[]] Params:' + str(param1) + \
                ',' + str(param2) + ' [[]] Result:' + result
         logfile.write(info + '\n')
         grinder.getStatistics().getForCurrentTest().setSuccess(False)
コード例 #2
0
 def sendRequest(self, param):
     """A method is called for each recorded page."""
     # print url + param
     response = request.GET(url + param)
     code = response.getStatusCode()
     print "code:", code
     data = response.getText().encode('utf-8')
     # print "data:", type(data)
     if code != 200 or data.find('_百度搜索') == -1:
         info = time.strftime(ISOTIMEFORMAT, time.localtime(time.time(
         ))) + ' Test:' + TEST_NAME + ' [[]] Param:' + param.encode(
             'utf-8') + ' [[]] StatusCode:' + str(
                 code) + ' [[]] Content:' + data
         logfile.write(info + '\n')
         grinder.getStatistics().getForCurrentTest().setSuccess(False)
コード例 #3
0
 def sendRequest(self, param):
     """A method is called for each recorded page."""
     # print url + param
     response = request.POST(
         '/async/translate?vet=10ahUKEwjKntXo1vHMAhUKH5QKHU2DDoQQqDgIJzAA..i&ei=Nb5DV4qwBIq-0ATNhrqgCA&yv=2',
         param)
     code = response.getStatusCode()
     print "code:", code
     data = response.getText().encode('utf-8')
     print "data:", data
     if code != 200 or data.find('tw-async-translate') == -1:
         info = time.strftime(ISOTIMEFORMAT, time.localtime(time.time(
         ))) + ' Test:' + TEST_NAME + ' [[]] Param:' + param.encode(
             'utf-8') + ' [[]] StatusCode:' + str(
                 code) + ' [[]] Content:' + data
         logfile.write(info + '\n')
         grinder.getStatistics().getForCurrentTest().setSuccess(False)
コード例 #4
0
    def report_step_status(cls, **kargs):

        success = kargs['success']
        __ctx = kargs['context']
        cause = kargs['cause']
        state = kargs['state']
        synchronous = kargs.get('synchronous', True)

        # Validation reporting
        response = kargs.get('response', None)
        if response and Configuration.outTraceActivated:
            reporting.outputTraceForValidation(__ctx, response)

        status = 'success'

        if Configuration.use_reporter:
            Configuration.getClientReporter().addNbCallCount(
                __ctx.line.getTestName())

        if success:
            logger.info('[state=%s][status=%s][cause=%s]%s' %
                        (state, status, cause, cls.localization(__ctx)))
            if synchronous:
                logger.trace('grinder.statistics.forLastTest.success = 1')
                grinder.statistics.forLastTest.success = 1
                grinder.getStatistics().report()

        else:
            status = 'failed'
            logger.error('[state=%s][status=%s][cause=%s]%s' %
                         (state, status, cause, cls.localization(__ctx)))
            if Configuration.use_reporter:
                Configuration.getClientReporter().addNbCallErrorCount(
                    __ctx.line.getTestName())

            if synchronous:
                try:
                    logger.trace('grinder.statistics.forLastTest.success = 0')
                    grinder.statistics.forLastTest.success = 0
                    grinder.getStatistics().report()
                except InvalidContextException, x:
                    logger.info(
                        'raise an InvalidContextException, meaning we are not in a post-processing of a grinder Test, reason: %s'
                        % (x))
コード例 #5
0
ファイル: guitools.py プロジェクト: cossme/grindertool
def parseJsonResult(result):
    errorFound = False

    json = JSONSerializer.toJSON(manageGzipFormat(result))
    try:
        iserror = json.getString("iserror")
        if iserror.lower() == 'true':
            errorFound = True
    except:
        print 'No tag iserror in the text JSON'
        print '%s' % (result.text)
        print '-' * 50

    if errorFound:
        statistics = grinder.getStatistics().getForCurrentTest()
        statistics.success = 0
コード例 #6
0
def modifyDefensively(targetIN,rdf,auth):
    attempts = 0
    log("modifying object defensively")
    while (attempts<5):
        result = HTTPRequest().PUT(targetIN,rdf,[auth])
        status = result.getStatusCode()
        if status >= 200 and status < 300:
            break
        else:
            log("failed attempt "+str(attempts))
            grinder.sleep(1000)
            attempts = attempts+1
            #todo sleep a while
    stats = grinder.getStatistics().getForCurrentTest()
    status = result.getStatusCode()
    if status >= 200 and status < 300:
        stats.setSuccess(True)
    else:
        log("failed to modifyDefensively, ended with status "+str(status))
        stats.setSuccess(False)
コード例 #7
0
        def processResponse(self, response):

            #threadContext = HTTPPluginControl.getThreadHTTPClientContext()
            #threadContext.resumeClock()

            # We just want to read data flow - so we can scale
            bodyLength = 0
            bin = BufferedInputStream(response.getInputStream())
            buf = jarray.zeros(8192, 'b')
            lenBuf = 0
            while lenBuf != -1:
                lenBuf = bin.read(buf)
                bodyLength += lenBuf
            bin.close()
            grinder.getLogger().output("INFO: Download of %d bytes finished" %
                                       (bodyLength))

            #threadContext.pauseClock();

            # Update statistics with body size
            testStatistics = grinder.getStatistics()
            if (testStatistics.isTestInProgress()):
                testStatistics.getForCurrentTest().addLong(
                    "httpplugin.responseLength", bodyLength)
コード例 #8
0
 def deleteResource(self, resourceType, resourceName, namespace):
     success = self.basicCli.deleteResource(resourceType, resourceName, namespace)
     if(not success):
         grinder.getStatistics().getForCurrentTest().setSuccess(False)
コード例 #9
0
 def reduceRC(self, rcName, namespace, replicas):
     success = self.syncCli.updateRC(rcName, namespace, replicas)
     if(not success):
         grinder.getStatistics().getForCurrentTest().setSuccess(False)
コード例 #10
0
 def createRC(self, rcName, namespace):
     success = self.syncCli.createRCWaitRunning(rcName, namespace)
     if(not success):
         grinder.getStatistics().getForCurrentTest().setSuccess(False)