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

[BUG] Fix test flakiness #1765

Merged
merged 1 commit into from
Feb 24, 2024
Merged

[BUG] Fix test flakiness #1765

merged 1 commit into from
Feb 24, 2024

Conversation

beggers
Copy link
Contributor

@beggers beggers commented Feb 23, 2024

Description of changes

Summarize the changes made by this PR.

The problem was subtle:

  • There are three places Collection state is stored: in Hypothesis's Bundle (== test data ~randomly generated according to our models), in our test's .model field, and in Chroma itself.
  • Each test step gets a random Collection from the Bundle. Our test code is responsible for doing stuff with it, modifying the test model, executing operations on Chroma itself, and verifying that model state matches Chroma's state.
  • Hypothesis's Bundle has (but no longer will once this PR lands) a full Collection model with all internal bookeeping, incl UUID and other fields. So we could have two Collections in the Bundle with the same name but different UUIDs or other fields. In our test's model and in Chroma, there would only be one Collection.
  • The bug arose when we updated metadata on one Bundle collection, on our model, and in Chroma; then tried to read metadata from another Bundle collection with the same name but different metadata. The fix to this was to read expected collection metadata from our test model, not from the Bundle. I changed line 204 to _metadata = self.model[coll.name] instead of _metadata = coll.metadata.
  • To save people others this grief in the future, I created a new ExternalCollection model which only contains externally visible Collection data. This simplifies Bundle state for this test and should make it easier to reason about in the future.
  • I also added the previously failing test cases to protect us from regressions. Since the model is much simpler now they don't give us much, but I feel better knowing they're there and laying the pattern for us to add future test cases.

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?

Copy link
Contributor Author

beggers commented Feb 23, 2024

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

Copy link

Please tag your PR title with one of: [ENH | BUG | DOC | TST | BLD | PERF | TYP | CLN | CHORE]. See https://docs.trychroma.com/contributing#contributing-code-and-ideas

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@beggers beggers changed the title Fix test flakiness [BUG] Fix test flakiness Feb 23, 2024
Copy link

Please tag your PR title with one of: [ENH | BUG | DOC | TST | BLD | PERF | TYP | CLN | CHORE]. See https://docs.trychroma.com/contributing#contributing-code-and-ideas

2 similar comments
Copy link

Please tag your PR title with one of: [ENH | BUG | DOC | TST | BLD | PERF | TYP | CLN | CHORE]. See https://docs.trychroma.com/contributing#contributing-code-and-ideas

Copy link

Please tag your PR title with one of: [ENH | BUG | DOC | TST | BLD | PERF | TYP | CLN | CHORE]. See https://docs.trychroma.com/contributing#contributing-code-and-ideas

@beggers beggers changed the title [BUG] Fix test flakiness [BUG]: Fix test flakiness Feb 23, 2024
Copy link

Please tag your PR title with one of: [ENH | BUG | DOC | TST | BLD | PERF | TYP | CLN | CHORE]. See https://docs.trychroma.com/contributing#contributing-code-and-ideas

@beggers beggers changed the title [BUG]: Fix test flakiness [BUG] Fix test flakiness Feb 23, 2024
Copy link

Please tag your PR title with one of: [ENH | BUG | DOC | TST | BLD | PERF | TYP | CLN | CHORE]. See https://docs.trychroma.com/contributing#contributing-code-and-ideas

@beggers beggers merged commit fd14f2d into main Feb 24, 2024
119 checks passed
if coll.name not in self.model:
with pytest.raises(Exception):
c = self.api.get_collection(name=coll.name)
return multiple()

c = self.api.get_collection(name=coll.name)
_metadata: Optional[Mapping[str, Any]] = coll.metadata
print("before API:", c)
Copy link
Collaborator

Choose a reason for hiding this comment

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

there is a print here

c.modify(metadata=_metadata, name=_name)
c = self.api.get_collection(name=coll.name)
print("after API:", c)
Copy link
Collaborator

Choose a reason for hiding this comment

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

there is a print here - please remove

@@ -236,18 +236,29 @@ def embedding_function_strategy(


@dataclass
class Collection:
class ExternalCollection:
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you document internal vs external?

atroyn pushed a commit to csbasil/chroma that referenced this pull request Apr 3, 2024
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
- Fix test flakiness mentioned in
chroma-core#1716 and seen after.

The problem was subtle:
- There are three places Collection state is stored: in Hypothesis's
Bundle (== test data ~randomly generated according to our models), in
our test's `.model` field, and in Chroma itself.
- Each test step gets a random Collection from the Bundle. Our test code
is responsible for doing stuff with it, modifying the test model,
executing operations on Chroma itself, and verifying that model state
matches Chroma's state.
- Hypothesis's Bundle has (but no longer will once this PR lands) a full
Collection model with all internal bookeeping, incl UUID and other
fields. So we could have two Collections in the Bundle with the same
name but different UUIDs or other fields. In our test's model and in
Chroma, there would only be one Collection.
- The bug arose when we updated metadata on one Bundle collection, on
our model, and in Chroma; then tried to read metadata from another
Bundle collection with the same name but different metadata. The fix to
this was to read expected collection metadata from our test model, not
from the Bundle. I changed line 204 to `_metadata =
self.model[coll.name]` instead of `_metadata = coll.metadata`.
- To save people others this grief in the future, I created a new
`ExternalCollection` model which only contains externally visible
Collection data. This simplifies Bundle state for this test and should
make it easier to reason about in the future.
- I also added the previously failing test cases to protect us from
regressions. Since the model is much simpler now they don't give us
much, but I feel better knowing they're there and laying the pattern for
us to add future test cases.

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python, `yarn test` for js

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants