다음을 통해 공유


애플리케이션이 제한을 제대로 처리하는지 테스트합니다.

API를 호스트하는 서버가 부하가 많은 경우에만 거의 발생하지 않으므로 테스트 제한이 어렵습니다. 개발자 프록시를 사용하여 모든 API에서 제한을 시뮬레이션하고 애플리케이션이 올바르게 처리하는지 확인할 수 있습니다.

모든 API에서 제한을 시뮬레이션하려면 GenericRandomErrorPlugin을 사용합니다. 사용하는 API가 헤더를 Retry-After 반환하는 경우 RetryAfterPlugin을 사용하여 API의 지시에 따라 앱이 백오프되는지 확인합니다.

모든 API에서 제한 시뮬레이션

시작하려면 개발자 프록시 구성 파일에서 사용하도록 설정합니다 GenericRandomErrorPlugin .

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/rc.schema.json",
  "plugins": [
    {
      "name": "GenericRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "errorsContosoApi",
      "urlsToWatch": [
        "https://api.contoso.com/*"
      ]
    }
  ]
}

다음으로, 시뮬레이션하려는 오류가 포함된 파일을 사용하도록 플러그 인을 구성합니다.

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/rc.schema.json",
  "plugins": [
    {
      "name": "GenericRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "errorsContosoApi",
      "urlsToWatch": [
        "https://api.contoso.com/*"
      ]
    }
  ],
  "errorsContosoApi": {
    "errorsFile": "errors-contoso-api.json"
  }
}

오류 파일에서 API의 실제 제한 응답과 일치되도록 제한 응답을 정의합니다.

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/genericrandomerrorplugin.schema.json",
  "errors": [
    {
      "request": {
        "url": "https://api.contoso.com/*"
      },
      "responses": [
        {
          "statusCode": 429,
          "headers": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ],
          "body": {
            "code": "TooManyRequests",
            "message": "Too many requests"
          }
        }
      ]
    }
  ]
}

구성 파일로 개발자 프록시를 시작하고 앱을 테스트하여 제한을 처리하는 방법을 확인합니다.

헤더를 Retry-After 사용하여 올바른 백업 테스트

많은 API는 응답 헤더를 Retry-After 사용하여 앱에 특정 시간 동안 백오프하도록 지시합니다. 개발자 프록시를 사용하여 제한 응답을 시뮬레이션할 때 헤더를 정적 값으로 구성 Retry-After 하거나 앱이 API를 다시 호출하기 전에 지침에 따라 대기하는지 테스트하는 동적 값을 사용할 수 있습니다.

헤더를 Retry-After 정적 값으로 구성하려면 제한 응답에 헤더를 추가합니다.

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/genericrandomerrorplugin.schema.json",
  "errors": [
    {
      "request": {
        "url": "https://api.contoso.com/*"
      },
      "responses": [
        {
          "statusCode": 429,
          "headers": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Retry-After",
              "value": "60"
            }
          ],
          "body": {
            "code": "TooManyRequests",
            "message": "Too many requests"
          }
        }
      ]
    }
  ]
}

이 예제에서는 헤더가 Retry-After 60초로 설정됩니다. 헤더를 정적 값으로 구성할 때 개발자 프록시는 앱이 API를 다시 호출하기 전에 대기하고 있는지 제어하지 않습니다.

API를 다시 호출하기 전에 앱이 올바르게 대기하고 있는지 테스트하려면 헤더의 값을 다음으로 @dynamic변경합니다.

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/genericrandomerrorplugin.schema.json",
  "errors": [
    {
      "request": {
        "url": "https://api.contoso.com/*"
      },
      "responses": [
        {
          "statusCode": 429,
          "headers": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Retry-After",
              "value": "@dynamic"
            }
          ],
          "body": {
            "code": "TooManyRequests",
            "message": "Too many requests"
          }
        }
      ]
    }
  ]
}

또한 .을 사용하여 개발 프록시 구성을 RetryAfterPlugin확장합니다.

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/rc.schema.json",
  "plugins": [
    {
      "name": "RetryAfterPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "urlsToWatch": [
        "https://api.contoso.com/*"
      ]
    },
    {
      "name": "GenericRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "errorsContosoApi",
      "urlsToWatch": [
        "https://api.contoso.com/*"
      ]
    }
  ],
  "errorsContosoApi": {
    "errorsFile": "errors-contoso-api.json"
  }
}

주의

RetryAfterPlugin 구성 파일에 앞을 GenericRandomErrorPlugin 추가합니다. 이후에 추가하면 요청을 처리할 기회가 있기 전에 RetryAfterPlugin 요청이 실패 GenericRandomErrorPlugin 합니다.

이 플러그 인은 제한 응답을 추적하고 여전히 제한된 API에 발급된 요청을 강제로 실패합니다.

자세한 정보