-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Clean up unified tests via skipping API #1551
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.mongodb.client.unified; | ||
|
||
import com.mongodb.assertions.Assertions; | ||
|
||
import static org.junit.jupiter.api.Assumptions.assumeFalse; | ||
|
||
public final class UnifiedTestSkips { | ||
|
||
private UnifiedTestSkips() {} | ||
|
||
public static TestDef testDef(final String dir, final String file, final String test) { | ||
return new TestDef(dir, file, test); | ||
} | ||
|
||
public static final class TestDef { | ||
private final String dir; | ||
private final String file; | ||
private final String test; | ||
|
||
private TestDef(final String dir, final String file, final String test) { | ||
this.dir = dir; | ||
this.file = file; | ||
this.test = test; | ||
} | ||
|
||
/** | ||
* Test is skipped because it is pending implementation, and there is | ||
* a Jira ticket tracking this which has more information. | ||
* | ||
* @param skip reason for skipping the test; must start with a Jira URL | ||
*/ | ||
public Skip skipJira(final String skip) { | ||
Assertions.assertTrue(skip.startsWith("https://jira.mongodb.org/browse/JAVA-")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the skip be due to a DRIVER-XXX ticket? I think checking against There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered this, but I think we need to have something our team is tracking. If a good counterexample comes up, we can remove the constraint at the time? |
||
return new Skip(this, skip); | ||
} | ||
|
||
/** | ||
* Test is skipped because the feature under test was deprecated, and | ||
* was removed in the Java driver. | ||
* | ||
* @param skip reason for skipping the test | ||
*/ | ||
public Skip skipDeprecated(final String skip) { | ||
return new Skip(this, skip); | ||
} | ||
|
||
/** | ||
* Test is skipped because the Java driver cannot comply with the spec. | ||
* | ||
* @param skip reason for skipping the test | ||
*/ | ||
public Skip skipNoncompliant(final String skip) { | ||
return new Skip(this, skip); | ||
} | ||
} | ||
|
||
public static final class Skip { | ||
private final TestDef testDef; | ||
private final String reason; | ||
|
||
private Skip(final TestDef testDef, final String reason) { | ||
this.testDef = testDef; | ||
this.reason = reason; | ||
} | ||
|
||
/** | ||
* All tests in file under dir skipped. | ||
* @param dir the directory name | ||
* @param file the test file's "description" field | ||
* @return this | ||
*/ | ||
public Skip file(final String dir, final String file) { | ||
boolean match = ("unified-test-format/" + dir).equals(testDef.dir) | ||
&& file.equals(testDef.file); | ||
assumeFalse(match, reason); | ||
return this; | ||
} | ||
|
||
/** | ||
* Test skipped if dir, file, and test match. | ||
* @param dir the directory name | ||
* @param file the test file's "description" field | ||
* @param test the individual test's "description" field | ||
* @return this | ||
*/ | ||
public Skip test(final String dir, final String file, final String test) { | ||
boolean match = ("unified-test-format/" + dir).equals(testDef.dir) | ||
&& file.equals(testDef.file) | ||
&& test.equals(testDef.test); | ||
assumeFalse(match, reason); | ||
return this; | ||
} | ||
|
||
/** | ||
* Test skipped if the test description contains the fragment as a substring | ||
* Avoid using this, except during development. | ||
* @param dir the directory name | ||
* @param fragment the substring to check in the test "description" field | ||
* @return this | ||
*/ | ||
public Skip testContains(final String dir, final String fragment) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be used carefully as it has the potential risk of skipping new tests matching the fragment... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add a note. I think we should stop it from being used in non-dev, but this will be more work, since existing tests use this pattern. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a use case where we want to filter by dir and test description as well? Thinking whether we should add an optional There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add it if we run into it (hopefully we don't, since as you say the contains methods seem risky). |
||
boolean match = ("unified-test-format/" + dir).equals(testDef.dir) | ||
&& testDef.test.contains(fragment); | ||
assumeFalse(match, reason); | ||
return this; | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
standalone-logging
here is the description of the test(s) https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/tests/unified/logging-standalone.json#L2 and not the JSON file name. The method defines the second parameter as the file https://github.com/mongodb/mongo-java-driver/pull/1551/files#diff-c703183de18b785f0df010e4d1dc57464f07946ae7e350533c507d4232801374R85I was under the impression that If one wants to exclude all tests under
logging-standalone.json
I could callIn contrary in https://github.com/mongodb/mongo-java-driver/pull/1551/files#diff-20c83c94232058f9e9a6b35b2c2825e600f5dba0cbc5a4c64bfd0aa78053cd28R46
serverMonitoringMode
is the actual JSON file name (which also matches its description)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the description used as an identifier is unfortunate. Probably tests should have an
id
field that matches their file name.Added param docs.