naver/ngrinder

The success and failure times of performance test results are inaccurate

mashuangwei opened this issue · 2 comments

1. Describe the bug 🐞

The success and failure times of each performance test result are inaccurate. For example, my pressure test interface inserts data. After 5 minutes of performance test, the performance test result succeeds 30000 times, and 30000 pieces of data are not inserted into the actual database. The same problem applies to the number of failures.

A clear and concise description of what the bug is.

2. Reproduction steps

  1. Create performance test plan

  2. Perform a 5-minute test

  3. Check the performance test results to verify whether the success and failure times are accurate'

3. Environment

  • Controller
    • OS: centos7
    • Browser: chrome 93
    • JDK version: 8
    • Controller version: 3.5.5 && 3.5.5-p
  • Agent
    • OS: centos7
    • JDK version : 8
    • Agent version: 3.5.5 && 3.5.5-p

4. Screenshots

If necessary, add screenshots to help explain your problem.

I think it's not the bug but your script problem.
To be clear, please post the script you used.

I think it's not the bug but your script problem. To be clear, please post the script you used.
It should be a defect. The test report shows that the number of executions is 23835, and the actual amount of data inserted into the application database is 24369. That is, the number of executions shown in the test report is less than the actual number

import static net.grinder.script.Grinder.grinder
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*
import net.grinder.script.GTest
import net.grinder.script.Grinder
import net.grinder.scriptengine.groovy.junit.GrinderRunner
import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
// import static net.grinder.util.GrinderUtils.* // You can use this if you're using nGrinder after 3.2.3
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith

import java.util.Date
import java.util.List
import java.util.ArrayList

import net.grinder.plugin.http.HTTPRequest
import net.grinder.plugin.http.HTTPPluginControl

import HTTPClient.Cookie
import HTTPClient.CookieModule
import HTTPClient.HTTPResponse
import HTTPClient.NVPair

// Uncomment this to use new experimental HTTP client.
// import org.ngrinder.http.HTTPRequest
// import org.ngrinder.http.HTTPResponse
// import org.ngrinder.http.cookie.Cookie
// import org.ngrinder.http.cookie.CookieManager

/**

  • A simple example using the HTTP plugin that shows the retrieval of a

  • single page via HTTP.

  • This script is automatically generated by ngrinder.

  • @author admin
    */
    @RunWith(GrinderRunner)
    class TestRunner {

    public static GTest test
    public static HTTPRequest request
    public static NVPair[] headers = []
    public static String body = "{\n "name": "张三",\n "id": "41849",\n "type": "小帅哥",\n "num": 10\n}"
    public static Cookie[] cookies = []

    @BeforeProcess
    public static void beforeProcess() {
    HTTPPluginControl.getConnectionDefaults().timeout = 6000
    test = new GTest(1, "10.20.101.58:8080")
    request = new HTTPRequest()
    // Set header datas
    List headerList = new ArrayList<>()
    headerList.add(new NVPair("Content-Type", "application/json"))
    headers = headerList.toArray()
    grinder.logger.info("before process.");
    }

    @BeforeThread
    public void beforeThread() {
    test.record(this, "test")
    grinder.statistics.delayReports=true;
    grinder.logger.info("before thread.");
    }

    @before
    public void before() {
    request.setHeaders(headers)
    cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) }
    grinder.logger.info("before. init headers and cookies");
    }

    @test
    public void test(){
    HTTPResponse result = request.POST("http://10.20.101.58:8080/order", body.getBytes())

     if (result.statusCode == 301 || result.statusCode == 302) {
     	grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode);
     } else {
     	assertThat(result.statusCode, is(200));
     }
    

    }
    }