Skip to content

DRIVERS-1713 Add ignoreExtraEvents to expectedEventsForClient #1153

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

Merged
merged 6 commits into from
Mar 9, 2022

Conversation

abr-egn
Copy link
Contributor

@abr-egn abr-egn commented Mar 1, 2022

DRIVERS-1713

This introduces an optional eventMatch field to the expectedEventsForClient struct, allowing tests to specify whether the expected events listed need to precisely match against actual events (the current behavior and the default for the field) or whether the events listed can be a prefix of actual events. The latter behavior is needed to convert the change stream spec tests, which rely on prefix matching in order to allow for unavoidable variance in getMore command count.

The Rust driver has implemented this logic here, and I have a branch with the tests introduced in this PR copied in and passing here.

@abr-egn abr-egn requested a review from a team as a code owner March 1, 2022 16:58
@abr-egn abr-egn requested review from jmikola and removed request for a team March 1, 2022 16:58
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

What legacy change stream test(s) actually required this functionality? I have some recollection of discussing this with @kmahar and thought that the extra events were only relevant on sharded clusters and could be avoided if we limited testing to replica sets (as I believe most of the legacy tests already do).

@@ -0,0 +1,15 @@
description: "expectedEventsForClient-additionalProperties"
Copy link
Member

Choose a reason for hiding this comment

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

Based on existing test files, The correct filename and description for this should be expectedEventsForClient-eventMatch-type.

I'd also suggest creating a separate expectedEventsForClient-eventType-enum test that uses a string value not found in the schema's enum (e.g. "foo").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, right. Fixed! Didn't add the -enum case because it's now a bool as per the other comment.

matched against the observed events. Valid values are ``exact``, meaning
that observed events after all specified events have matched MUST cause a
test failure, and ``prefix``, meaning that observed events after all
specified events have been matched MUST NOT cause a test failure.
Copy link
Member

Choose a reason for hiding this comment

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

With respect to the Defy Augury mantra, is it likely that additional matching strategies will be needed down the line? If not, I think this might make more sense as an ignoreExtraEvents boolean that defaults to false.

If that change is made, the only necessary invalid test would be expectedEventsForClient-ignoreExtraEvents-type with a non-boolean value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense; I certainly see no needs for future matching modes, and it's hard to imagine what reasonable ones would even be. Updated.

@abr-egn
Copy link
Contributor Author

abr-egn commented Mar 4, 2022

Quite a few of the tests are written to implicitly rely on the prefix matching even without the variance in getMore, e.g. they only check for an initial aggregate command to validate the syntax.

In the initial discussions that I was part of, restricting the tests to replica sets didn't come up as an option; the small additive change to the unified test spec to allow prefixes had general consensus as a reasonable path forward. With that as background I implemented DRIVERS-1713 as a semi-automated conversion rather than a rewrite.

It might be possible to remove the need for the unified test change by updating those tests that fail under exact matching, either by filling out the full set of expected events or restricting them to replsets or both; that has the downsides of making the tests somewhat more brittle and reducing their coverage, as well as the extra engineering time that would take.

@kmahar
Copy link
Contributor

kmahar commented Mar 4, 2022

@jmikola for reference we discussed this previously here: https://mongodb.slack.com/archives/G7U1QFDPE/p1643133976071300

by my count the majority of legacy tests (38 of 52) are currently run against sharded topologies, and it seems like any test that iterates a change stream (most/all of them, I think?) would be susceptible to the extra getMores issue, so it does seem like we would lose a lot of coverage if we stopped testing against sharded clusters

@jmikola
Copy link
Member

jmikola commented Mar 4, 2022

Points noted. I just re-read that Slack thread (thanks for digging it up) and in light of that this seems like a reasonable change. I'm glad we don't have to worry about ignoring events within the sequence (as discussed in that thread).

So I have no objections to this change, but my two comments above on the diff do apply. I wonder if a boolean flag makes more sense for this, unless we really think there will be a need to implement different matching strategies via the enum.

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

New changes LGTM w/ one suggestion. Thanks, @abr-egn!

@@ -3281,6 +3287,8 @@ spec changes developed in parallel or during the same release cycle.
Change Log
==========

:2022-03-01: Add ``eventMatch`` field to ``expectedEventsForClient``.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
:2022-03-01: Add ``eventMatch`` field to ``expectedEventsForClient``.
:2022-03-01: Add ``ignoreExtraEvents`` field to ``expectedEventsForClient``.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, fixed!

@abr-egn abr-egn force-pushed the DRIVERS-1713/eventMatch branch from bac6217 to c9c5e91 Compare March 8, 2022 15:04
@abr-egn abr-egn changed the title DRIVERS-1713 Add eventMatch to expectedEventsForClient DRIVERS-1713 Add ignoreExtraEvents to expectedEventsForClient Mar 8, 2022
@abr-egn abr-egn merged commit ff0c705 into mongodb:master Mar 9, 2022
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.

3 participants