Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stateful API testing for Model Registry #132

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lugi0
Copy link
Collaborator

@lugi0 lugi0 commented Feb 7, 2025

Description

This adds a test for stateful API testing of Model Registry. It also bumps Schemathesis to V4, which is still an alpha release but appears to work fine for this workload.
I will keep this as a draft until the openAPI spec is updated in the Model Registry repo to support Stateful testing, and we can then decide if we are ok with an alpha release being pulled or if we want to wait / downgrade to V3 (requires some rework due to breaking changes between the two major versions).
I have also added a new mark type, "fuzzer", which I'd use to indicate tests which are bound to fail due to their random nature.

How Has This Been Tested?

Multiple runs made from local with an updated openAPI spec file which have already identified some failures to address in Model Registry.

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@lugi0 lugi0 self-assigned this Feb 7, 2025
Copy link

github-actions bot commented Feb 7, 2025

The following are automatically added/executed:

Available user actions:

  • To mark a PR as WIP, add /wip in a comment. To remove it from the PR comment /wip cancel to the PR.
  • To block merging of a PR, add /hold in a comment. To un-block merging of PR comment /hold cancel.
  • To mark a PR as approved, add /lgtm in a comment. To remove, add /lgtm cancel.
    lgtm label removed on each new commit push.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
Supported labels

{'/wip', '/lgtm', '/hold', '/verified'}

@lugi0
Copy link
Collaborator Author

lugi0 commented Feb 7, 2025

On hold until kubeflow/model-registry#773 is merged

# @pytest.fixture(scope="class")
# def generated_schema_local(model_registry_instance_rest_endpoint):
# schema = schemathesis.openapi.from_path(
# path="utilities/manifests/model-registry-api.yaml",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please set path in py_config so when a user wants to overwrite they can us tc=:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure to which scenario this would apply, this needs to be manually enabled and pointing to an updated openapi spec, I don't think it makes sense to have it exposed as a config variable.


def after_call(self, response: Response, case: Case) -> None:
LOGGER.info(
"%s %s -> %d",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use f-string formatting

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove as not needed



@pytest.fixture
def state_machine(generated_schema: BaseOpenAPISchema, current_client_token: str) -> APIStateMachine:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a regular function; there's no setup / teardown related to the test here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schemathesis' documentation recommends using a fixture when loading the schema lazily: https://schemathesis.readthedocs.io/en/stable/stateful.html#schemathesis.stateful.state_machine.APIStateMachine.validate_response

Comment on lines +10 to +11
@pytest.mark.fuzzer
@pytest.mark.sanity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use pytestmark to set all markers in the same place.

# Once it is updated to support Stateful testing of the API we can enable this to run every time,
# but for now having it run manually to check the existing failures is more than enough.
@pytest.mark.skip(reason="Only run manually for now")
@pytest.mark.fuzzer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i do not think that sanity tests should be marked as fuzzer; sanity tests are a set of tests to check basic functionality. fuzzing (or in this case tools which are based on it) is a different level of testing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proper functioning of the API is basic functionality IMHO. We can exclude the "fuzzer" mark if we don't want to see these failures, that's why I'm setting both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants