import { configSchema } from './config' ; describe ( 'config validation' , ( ) => { test ( 'task manager defaults' , ( ) => { const config = { } ; expect ( configSchema . validate ( config ) ) . toMatchInlineSnapshot ( `
      Object {
        "ephemeral_tasks": Object {
          "enabled": false,
          "request_capacity": 10,
        },
        "max_attempts": 3,
        "max_poll_inactivity_cycles": 10,
        "max_workers": 10,
        "monitored_aggregated_stats_refresh_rate": 60000,
        "monitored_stats_health_verbose_log": Object {
          "enabled": false,
          "warn_delayed_task_start_in_seconds": 60,
        },
        "monitored_stats_required_freshness": 4000,
        "monitored_stats_running_average_window": 50,
        "monitored_task_execution_thresholds": Object {
          "custom": Object {},
          "default": Object {
            "error_threshold": 90,
            "warn_threshold": 80,
          },
        },
        "poll_interval": 3000,
        "request_capacity": 1000,
        "unsafe": Object {
          "exclude_task_types": Array [],
        },
        "version_conflict_threshold": 80,
      }
    ` ) ; } ) ; test ( 'the required freshness of the monitored stats config must always be less-than-equal to the poll interval' , ( ) => { const config = { monitored_stats_required_freshness : 100 , } ; expect ( ( ) => { configSchema . validate ( config ) ; } ) . toThrowErrorMatchingInlineSnapshot ( `"The specified monitored_stats_required_freshness (100) is invalid, as it is below the poll_interval (3000)"` ) ; } ) ; test ( 'the default required freshness of the monitored stats is poll interval with a slight buffer' , ( ) => { const config = { } ; expect ( configSchema . validate ( config ) ) . toMatchInlineSnapshot ( `
      Object {
        "ephemeral_tasks": Object {
          "enabled": false,
          "request_capacity": 10,
        },
        "max_attempts": 3,
        "max_poll_inactivity_cycles": 10,
        "max_workers": 10,
        "monitored_aggregated_stats_refresh_rate": 60000,
        "monitored_stats_health_verbose_log": Object {
          "enabled": false,
          "warn_delayed_task_start_in_seconds": 60,
        },
        "monitored_stats_required_freshness": 4000,
        "monitored_stats_running_average_window": 50,
        "monitored_task_execution_thresholds": Object {
          "custom": Object {},
          "default": Object {
            "error_threshold": 90,
            "warn_threshold": 80,
          },
        },
        "poll_interval": 3000,
        "request_capacity": 1000,
        "unsafe": Object {
          "exclude_task_types": Array [],
        },
        "version_conflict_threshold": 80,
      }
    ` ) ; } ) ; test ( 'the custom monitored_task_execution_thresholds can be configured at task type' , ( ) => { const config = { monitored_task_execution_thresholds : { custom : { 'alerting:always-fires' : { error_threshold : 50 , warn_threshold : 30 , } , } , } , } ; expect ( configSchema . validate ( config ) ) . toMatchInlineSnapshot ( `
      Object {
        "ephemeral_tasks": Object {
          "enabled": false,
          "request_capacity": 10,
        },
        "max_attempts": 3,
        "max_poll_inactivity_cycles": 10,
        "max_workers": 10,
        "monitored_aggregated_stats_refresh_rate": 60000,
        "monitored_stats_health_verbose_log": Object {
          "enabled": false,
          "warn_delayed_task_start_in_seconds": 60,
        },
        "monitored_stats_required_freshness": 4000,
        "monitored_stats_running_average_window": 50,
        "monitored_task_execution_thresholds": Object {
          "custom": Object {
            "alerting:always-fires": Object {
              "error_threshold": 50,
              "warn_threshold": 30,
            },
          },
          "default": Object {
            "error_threshold": 90,
            "warn_threshold": 80,
          },
        },
        "poll_interval": 3000,
        "request_capacity": 1000,
        "unsafe": Object {
          "exclude_task_types": Array [],
        },
        "version_conflict_threshold": 80,
      }
    ` ) ; } ) ; test ( 'the monitored_task_execution_thresholds ensures that the default warn_threshold is lt the default error_threshold' , ( ) => { const config = { monitored_task_execution_thresholds : { default : { warn_threshold : 80 , error_threshold : 70 , } , } , } ; expect ( ( ) => { configSchema . validate ( config ) ; } ) . toThrowErrorMatchingInlineSnapshot ( `"[monitored_task_execution_thresholds.default]: warn_threshold (80) must be less than, or equal to, error_threshold (70)"` ) ; } ) ; test ( 'the monitored_task_execution_thresholds allows the default warn_threshold to equal the default error_threshold' , ( ) => { const config = { monitored_task_execution_thresholds : { default : { warn_threshold : 70 , error_threshold : 70 , } , } , } ; expect ( ( ) => { configSchema . validate ( config ) ; } ) . not . toThrowError ( ) ; } ) ; test ( 'the monitored_task_execution_thresholds ensures that the warn_threshold is lte error_threshold on custom thresholds' , ( ) => { const config = { monitored_task_execution_thresholds : { custom : { 'alerting:always-fires' : { error_threshold : 80 , warn_threshold : 90 , } , } , } , } ; expect ( ( ) => { configSchema . validate ( config ) ; } ) . toThrowErrorMatchingInlineSnapshot ( `"[monitored_task_execution_thresholds.custom.alerting:always-fires]: warn_threshold (90) must be less than, or equal to, error_threshold (80)"` ) ; } ) ; test ( 'the monitored_task_execution_thresholds allows a custom error_threshold which is lower than the default warn_threshold' , ( ) => { const config = { monitored_task_execution_thresholds : { default : { warn_threshold : 80 , error_threshold : 90 , } , custom : { 'alerting:always-fires' : { error_threshold : 60 , warn_threshold : 50 , } , } , } , } ; expect ( ( ) => { configSchema . validate ( config ) ; } ) . not . toThrowError ( ) ; } ) ; } ) ;