|
1 | 1 | import pytest
|
| 2 | +import turing |
2 | 3 | from turing.generated.exceptions import ApiValueError
|
3 | 4 | from turing.router.config.common.env_var import EnvVar
|
4 | 5 | from turing.router.config.autoscaling_policy import (
|
|
13 | 14 | NopRouterEnsemblerConfig,
|
14 | 15 | PyfuncRouterEnsemblerConfig,
|
15 | 16 | DockerRouterEnsemblerConfig,
|
| 17 | + EnsemblerStandardConfig, |
16 | 18 | StandardRouterEnsemblerConfig,
|
17 | 19 | InvalidExperimentMappingException,
|
18 | 20 | )
|
19 | 21 |
|
20 |
| - |
21 | 22 | @pytest.mark.parametrize(
|
22 | 23 | "id,type,standard_config,docker_config,expected",
|
23 | 24 | [
|
@@ -544,6 +545,102 @@ def test_create_nop_router_ensembler_config_with_invalid_route(
|
544 | 545 | with pytest.raises(expected):
|
545 | 546 | router.to_open_api()
|
546 | 547 |
|
| 548 | +@pytest.mark.parametrize( |
| 549 | + "ensembler_type,config,expected", |
| 550 | + [ |
| 551 | + pytest.param( |
| 552 | + "nop", |
| 553 | + "nop_router_ensembler_config", |
| 554 | + { |
| 555 | + "nop_config": EnsemblerNopConfig(final_response_route_id="test"), |
| 556 | + "type": "nop" |
| 557 | + }, |
| 558 | + ), |
| 559 | + pytest.param( |
| 560 | + "standard", |
| 561 | + "standard_router_ensembler_config_with_experiment_mappings", |
| 562 | + { |
| 563 | + "standard_config": EnsemblerStandardConfig( |
| 564 | + fallback_response_route_id="route-1", |
| 565 | + experiment_mappings=[ |
| 566 | + turing.generated.models.EnsemblerStandardConfigExperimentMappings( |
| 567 | + experiment="experiment-1", route="route-1", treatment="treatment-1", |
| 568 | + ), |
| 569 | + turing.generated.models.EnsemblerStandardConfigExperimentMappings( |
| 570 | + experiment="experiment-2", route="route-2", treatment="treatment-2", |
| 571 | + ), |
| 572 | + ], |
| 573 | + route_name_path=None, |
| 574 | + lazy_routing=False, |
| 575 | + ), |
| 576 | + "type": "standard" |
| 577 | + }, |
| 578 | + ), |
| 579 | + pytest.param( |
| 580 | + "standard", |
| 581 | + "standard_router_ensembler_config_with_route_name_path", |
| 582 | + { |
| 583 | + "standard_config": EnsemblerStandardConfig( |
| 584 | + fallback_response_route_id="route-1", |
| 585 | + experiment_mappings=None, |
| 586 | + route_name_path="route_name", |
| 587 | + lazy_routing=False, |
| 588 | + ), |
| 589 | + "type": "standard" |
| 590 | + }, |
| 591 | + ), |
| 592 | + pytest.param( |
| 593 | + "docker", |
| 594 | + "generic_ensembler_docker_config", |
| 595 | + { |
| 596 | + "docker_config": turing.generated.models.EnsemblerDockerConfig( |
| 597 | + autoscaling_policy=turing.generated.models.AutoscalingPolicy(metric="memory", target="80"), |
| 598 | + endpoint="http://localhost:5000/ensembler_endpoint", |
| 599 | + env=[turing.generated.models.EnvVar(name="env_name", value="env_val")], |
| 600 | + image="test.io/just-a-test/turing-ensembler:0.0.0-build.0", |
| 601 | + port=5120, |
| 602 | + resource_request=turing.generated.models.ResourceRequest( |
| 603 | + cpu_request="100m", max_replica=3, |
| 604 | + memory_request="512Mi", min_replica=1, |
| 605 | + ), |
| 606 | + service_account="secret-name-for-google-service-account", |
| 607 | + timeout="500ms" |
| 608 | + ), |
| 609 | + "type": "docker" |
| 610 | + }, |
| 611 | + ), |
| 612 | + pytest.param( |
| 613 | + "pyfunc", |
| 614 | + "generic_ensembler_pyfunc_config", |
| 615 | + { |
| 616 | + "pyfunc_config": turing.generated.models.EnsemblerPyfuncConfig( |
| 617 | + autoscaling_policy=turing.generated.models.AutoscalingPolicy(metric="concurrency", target="10"), |
| 618 | + ensembler_id=11, |
| 619 | + env=[turing.generated.models.EnvVar(name="env_name", value="env_val")], |
| 620 | + project_id=77, |
| 621 | + resource_request=turing.generated.models.ResourceRequest( |
| 622 | + cpu_request="100m", max_replica=3, |
| 623 | + memory_request="512Mi",min_replica=1, |
| 624 | + ), |
| 625 | + timeout="500ms" |
| 626 | + ), |
| 627 | + "type": "pyfunc" |
| 628 | + }, |
| 629 | + ), |
| 630 | + ], |
| 631 | +) |
| 632 | +def test_create_base_ensembler(ensembler_type, config, expected, request): |
| 633 | + config_data = request.getfixturevalue(config) |
| 634 | + ensembler_config = None |
| 635 | + if ensembler_type == "nop": |
| 636 | + ensembler_config = RouterEnsemblerConfig(type=ensembler_type, nop_config=config_data) |
| 637 | + elif ensembler_type == "standard": |
| 638 | + ensembler_config = RouterEnsemblerConfig(type=ensembler_type, standard_config=config_data) |
| 639 | + elif ensembler_type == "docker": |
| 640 | + ensembler_config = RouterEnsemblerConfig(type=ensembler_type, docker_config=config_data) |
| 641 | + elif ensembler_type == "pyfunc": |
| 642 | + ensembler_config = RouterEnsemblerConfig(type=ensembler_type, pyfunc_config=config_data) |
| 643 | + assert ensembler_config.to_dict() == expected |
547 | 644 |
|
548 | 645 | @pytest.mark.parametrize(
|
549 | 646 | "cls,config,expected",
|
|
0 commit comments