通过


你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Azure 负载测试资源中创建负载测试

测试指定用于运行负载测试的测试脚本和配置设置。 可以在 Azure 负载测试资源中创建一个或多个测试。

负载测试的配置包括:

在 Azure 负载测试中,负载测试创建和文件上传是分离的,即它们是单独的 API作。 本部分显示创建负载测试所涉及的步骤。

  1. 获取 Azure 负载测试资源的终结点或数据平面 URI,如下 所述

  2. 创建新的测试

    PATCH https://{Endpoint}/tests/{testId}?api-version=2022-11-01
    

    对于使用此签名发出请求的客户端,将执行 “负载测试管理 - 创建或更新测试 ”作。

    使用此签名发出的请求的成功响应将类似于以下内容:

    {
      "description": "sample description",
      "displayName": "Performance_LoadTest",
      "loadTestConfiguration": {
        "engineInstances": 6,
        "splitAllCSVs": true
      },
      "passFailCriteria": {
        "passFailMetrics": {
          "fefd759d-7fe8-4f83-8b6d-aeebe0f491fe": {
            "clientMetric": "response_time_ms",
            "aggregate": "percentage",
            "condition": ">",
            "value": 20,
            "action": "continue"
          }
        }
      },
      "secrets": {
        "secret1": {
          "value": "https://samplevault.vault.azure.net/secrets/samplesecret/f113f91fd4c44a368049849c164db827",
          "type": "AKV_SECRET_URI"
        }
      },
      "environmentVariables": {
        "envvar1": "sampletext"
      },
      "subnetId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/samplerg/providers/Microsoft.Network/virtualNetworks/samplenetworkresource/subnets/AAAAA0A0A0",
      "keyvaultReferenceIdentityType": "UserAssigned",
      "keyvaultReferenceIdentityId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/samplerg/providers/sampleprovider/sampleresourcetype/sampleresourcename"
    }
    

    这将更新测试详细信息,例如测试名称、描述、机密、环境变量、引擎数量和通过/失败条件。

  3. 将文件上传到创建的测试

    PUT https://{Endpoint}/tests/{testId}/files/{fileName}?api-version=2022-11-01
    

    PUT https://{Endpoint}/tests/{testId}/files/{fileName}?fileType={fileType}&api-version=2022-11-01
    

    对于使用此签名发出请求的客户端,将执行 “负载测试管理 - 上传测试文件” 作。

    注释

    每个 PUT 调用仅支持上传 1 个文件。 如果在同一调用中上传了多个文件,则除第一个文件外的所有文件都将被丢弃。 根据要求,您可能需要进行多次调用,每个调用一个,即 JMX 脚本、ZIP 文件、CSV 文件、user.properties 等。

    上传的 JMX 文件是否符合 XML 规范并且是否是有效的 JMeter 脚本,则会进行验证。 validationStatus 字段显示验证的状态。 如果 JMeter 能够接受 JMX 脚本而不会出现任何错误,则将其视为“VALIDATION_SUCCESS”,并且该文件已成功与负载测试相关联。 所有后续测试运行都将使用此文件。

    使用此签名发出的请求的成功响应将类似于以下内容:

        {
      "url": "https://dummyurl.com/testscriptresource",
      "fileName": "sample.jmx",
      "fileType": "ADDITIONAL_ARTIFACTS",
      "expireDateTime": "2021-12-05T16:43:46.072Z",
      "validationStatus": "VALIDATION_SUCCESS"
    }
    
  4. 使用以下步骤在测试中配置应用组件以监视服务器端指标。

    PATCH https://{Endpoint}/tests/{testId}/app-components?api-version=2022-11-01
    

    对于使用此签名发出请求的客户端,将执行 “负载测试管理 - 创建或更新应用组件” 作。 请求正文应包含 testId 或 testRunId。

    使用此签名发出的请求的成功响应将类似于以下内容:

        {
      "testId": "12345678-1234-1234-1234-123456789012",
      "components": {
        "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/samplerg/providers/microsoft.insights/components/appcomponentresource": {
          "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/samplerg/providers/microsoft.insights/components/appcomponentresource",
          "resourceType": "microsoft.insights/components",
          "resourceName": "appcomponentresource",
          "displayName": "Performance_LoadTest_Insights",
          "resourceGroup": "samplerg",
          "subscriptionId": "00000000-0000-0000-0000-000000000000",
          "kind": "web"
        }
      },
      "createdDateTime": "2021-12-05T16:43:46.072Z",
      "createdBy": "user@contoso.com",
      "lastModifiedDateTime": "2021-12-05T16:43:46.072Z",
      "lastModifiedBy": "user@contoso.com"
    }