다음을 통해 공유


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

테스트 제한은 API를 호스트하는 서버가 부하가 많은 경우에만 드물게 발생하기 때문에 어렵습니다. 개발자 프록시를 사용하여 모든 API에서 제한을 시뮬레이션하고 애플리케이션이 올바르게 처리하는지 검사 수 있습니다.

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

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

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

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.14.1/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/microsoft/dev-proxy/main/schemas/v0.14.1/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/microsoft/dev-proxy/main/schemas/v0.14.1/genericrandomerrorplugin.schema.json",
  "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/microsoft/dev-proxy/main/schemas/v0.14.1/genericrandomerrorplugin.schema.json",
  "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/microsoft/dev-proxy/main/schemas/v0.14.1/genericrandomerrorplugin.schema.json",
  "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/microsoft/dev-proxy/main/schemas/v0.14.1/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에 발급된 요청을 강제로 실패합니다.

추가 정보