-
Notifications
You must be signed in to change notification settings - Fork 165
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
GH-4592 Replace a Junit4 Suite with v5 DynamicTest #4593
GH-4592 Replace a Junit4 Suite with v5 DynamicTest #4593
Conversation
@abrokenjester I think I got the upgrade of the manifest based tests to junit5 done. I removed some old deprecated test classes now that we are going to go to v5 as they are not compatible. They would need a similar non compatible rewrite to make work. |
@JervenBolleman I'll try to take at look at this as soon as I can. |
@hmottestad I am rebasing this so that you don't need to deal with the mergeconflicts. |
Thanks! |
ef38ad4
to
8c33d62
Compare
@hmottestad the verify/integration-tests stage passes on my laptop. However, it does fail on my desktop with the same error as given by the github action :( |
@kenwenzel would you mind having a look at this failure. The tests pass for native and memory on all my systems. However, on my desktop and the github action I have strange errors. One difference is that my laptop is fedora while desktop and github action are ubuntu based. |
Hi @JervenBolleman, the NPEs are due to lazy values. Maybe the hash code function tries to initialize these values after the store has already been closed. This should ensure that values do not leave the SAIL in an uninitialized state. |
@kenwenzel @hmottestad I found that part of the reason is that these tests now run concurrently and where sharing state. I fixed just this and will push a new commit. |
e9d57aa
to
f289202
Compare
tests.toArray(result); | ||
|
||
return result; | ||
public Collection<DynamicTest> tests() { |
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.
I believe that this needs the @testfactory annotation. IntelliJ doesn't seem to pick up the annotation on the abstract method.
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.
Probably applies to other similar methods too.
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.
I think it is actually an error in the manifest file itself. There is a query that looks for mf:include
but the manifest file for geosparql uses mf:entities
and even a different IRI prefix for mf:
. Let me have a look.
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.
Looking at a current develop integration test job I think these tests are not run at this time either...
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-failsafe-plugin:3.1.2:verify (verify) @ rdf4j-geosparql-compliance ---
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.
Reenabled these tests. Lucky they all pass :)
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.
There are several other similar methods that were missing the @testfactory annotation. Did you look over the rest of the code?
|
||
public Stream<DynamicTest> tests() { | ||
return Stream.of(makeTest("GH4499BindFilterNotExist2", this::testGH4499BindFilterNotExist2), | ||
makeTest("GH4499BindFilterNotExist1", this::testGH4499BindFilterNotExist1), | ||
makeTest("GH3696Bind", this::testGH3696Bind), makeTest("SelectBindOnly", this::testSelectBindOnly), | ||
makeTest("SES2250BindErrorsInPath", this::testSES2250BindErrorsInPath), | ||
makeTest("SES2250BindErrors", this::testSES2250BindErrors), | ||
makeTest("BindScopeUnion", this::testBindScopeUnion), makeTest("BindScope", this::testBindScope), | ||
makeTest("BindError", this::testBindError)); | ||
} |
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.
Is there no way to stick with the regular @test annotation? Or maybe generate this list of tests in a more automatic way?
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.
I couldn't figure it out from the documentation :(
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.
ChatGPT recommends this:
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.stream.Stream;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.junit.jupiter.api.DynamicTest;
public class BindTest extends AbstractComplianceTest {
// ... existing methods ...
public Stream<DynamicTest> tests() {
// You may need to adjust how the repository connection is obtained
Repository repo = getRepository(); // Or however you obtain a repository instance
RepositoryConnection conn = repo.getConnection();
return Arrays.stream(BindTest.class.getDeclaredMethods())
.filter(method -> shouldRunAsTest(method))
.map(method -> createDynamicTestFromMethod(method, conn));
}
private boolean shouldRunAsTest(Method method) {
// Check if the method is a test method and takes a RepositoryConnection as argument
return method.getName().startsWith("test") &&
method.getParameterCount() == 1 &&
method.getParameterTypes()[0] == RepositoryConnection.class;
}
private DynamicTest createDynamicTestFromMethod(Method method, RepositoryConnection conn) {
return DynamicTest.dynamicTest(method.getName(), () -> {
try {
method.invoke(BindTest.this, conn);
} catch (Exception e) {
throw e.getCause();
}
});
}
private Repository getRepository() {
// Implement this method to return your Repository instance
return ...;
}
}
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.
Dunno how pretty that is though.
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.
That's going back to junit v2 ;) I don't mind, the official way is to generate some kind of test template. But it is a lot of work for a little gain. @hmottestad Is it ok if we merge as is and leave that as a todo?
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.
I guess we can always change it up later, and your approach does allow IntelliJ to run a single test instead of having to run the entire suite.
Also replaces a static so more tests should be runnable in parallel in the future. Signed-off-by: Jerven Bolleman <[email protected]>
Also delete some deprecated tests classes that are no longer compatible with the junit5 way of doing things. Signed-off-by: Jerven Bolleman <[email protected]>
Signed-off-by: Jerven Bolleman <[email protected]>
Signed-off-by: Jerven Bolleman <[email protected]>
Allow for non DAWG approved tests to run. Adds a manifest-all.ttl file for geosparql like sparql 1.1. compliance. Also remove some unused imports. Signed-off-by: Jerven Bolleman <[email protected]>
4f3ba48
to
da3e01e
Compare
@hmottestad sorry for the force push to undo the merge commit :( |
I believe that the missing annotation was not the problem. For me other
classes with eclipse it works with just the annotation on the super super
class. I am going to make sure they ran in the logs to be sure.
…On Fri, Nov 10, 2023, 17:30 Håvard M. Ottestad ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
testsuites/geosparql/src/main/java/org/eclipse/rdf4j/testsuite/query/algebra/geosparql/GeoSPARQLManifestTest.java
<#4593 (comment)>:
> - manifests.add(
- GeoSPARQLManifestTest.class.getClassLoader()
- .getResource("testcases-geosparql/functions/manifest.ttl")
- .toExternalForm());
- while (!manifests.isEmpty()) {
- String pop = manifests.pop();
- SPARQLQueryTestManifest manifest = new SPARQLQueryTestManifest(pop, null, false);
- tests.addAll(manifest.getTests());
- manifests.addAll(manifest.getSubManifests());
- }
-
- Object[][] result = new Object[tests.size()][6];
- tests.toArray(result);
-
- return result;
+ public Collection<DynamicTest> tests() {
There are several other similar methods that were missing the @testfactory
<https://github.com/testfactory> annotation. Did you look over the rest
of the code?
—
Reply to this email directly, view it on GitHub
<#4593 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHQYFJ77D5YYXEWO5T5AALYDZJDRAVCNFSM6AAAAAAYKM6VKCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTOMRVGE2TINRUHE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@hmottestad you where completely right I had missed a |
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.
@JervenBolleman thanks for these fixes! You can go ahead and merge when you want.
Also replaces a static so more tests should be runnable in parallel in the future.
GitHub issue closes #4592
PR Author Checklist (see the contributor guidelines for more details):
mvn process-resources
to format from the command line)