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

[WFCORE-7043] Subsystem-level testing of core-managment is incomplete #6235

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

lvydra
Copy link
Contributor

@lvydra lvydra commented Nov 7, 2024

@wildfly-ci

This comment was marked as off-topic.

Comment on lines +7 to +12
<process-state-listener name="x" class="org.acme.foo.MyClass" module="org.acme.foo" timeout="${process.timeout:5000}">
<properties>
<property name="foo" value="true"/>
<property name="bar" value="${bar.prop:2}"/>
</properties>
</process-state-listener>
Copy link
Collaborator

Choose a reason for hiding this comment

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

@lvydra You also need to add the test case that reads the subsystem with the expression resolved and assert that the values resolved are the expected ones.

Comment on lines 69 to 68
private Object getValue(ModelNode node, String attributeName) {
ModelNode result = node.get(attributeName).resolve();
return result.asString();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reviewing this I've just learnt that Elytron tests (e.g ResolveExpressionAttributesTestCase) use the same approach you did here. However, this is a weak test. What we are testing here is just how the ModelNode resolves expressions.

What I was expecting instead is to read the resource with the expressions resolved so we can getin the operation result the expressions resolved by the server code, hence we will be testing the expression resolution of the read operation with this subsystem instead of just testing that the ModelNode object is able to resolve an expression.

@lvydra Do you follow me on this and do you agree? For your info, I've found this example of what we should be testing here https://github.com/wildfly/wildfly/blob/main/naming/src/test/java/org/jboss/as/naming/subsystem/NamingSubsystemTestCase.java#L113-L117

I'm going to open a Jira for ResolveExpressionAttributesTestCase since in my opinion it should be hardened testing the server code expression resolution and not the ModelNode object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yersan Now that I see it, I have to agree. I'll look into it.

@bstansberry
Copy link
Contributor

Thanks @lvydra for taking on this JIRA.

I wasn't asking that we validate the expression resolution in the individual test. We just need to ensure that in the files we use for the executions of AbstractSubsystemBaseTest.standardSubsystemTest for every schema version and every attribute we use an expression (if the attribute is of a nature that should support expressions). This is just a simple good practice to help guard against mistakes.

I think adding logic to validate expression resolution beyond whatever already happens in standardSubsystemTest should be a separate task, and done as shared logic in AbstractSubsystemBaseTest or some similar base thing. Individual subsystem tests shouldn't need to deal with it directly. NOTE: I'm not asking anyone to do that; I'm just looking for the addition of expressions so what's already there is exercised and others looking at the files get a sense of the general best practice.

NOTE: if this PR has a working validation in CoreManagementSubsystemTestCase, I'm not suggesting it be removed. ^^^ is only relevant if getting the validation done is blocking things.

@lvydra lvydra requested a review from yersan November 15, 2024 08:23
Copy link
Collaborator

@yersan yersan left a comment

Choose a reason for hiding this comment

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

I think it would have been better to assert a value resolved instead of getting the default if doesn't exist, but it should be ok as it is. Following Brian's note, expression resolution in individual tests should not block this, so I'm approving this from my side. Thanks @lvydra

This is just a simple good practice to help guard against mistakes.

@bstansberry ok, so following your comment, my understanding is that the inclusion of these expressions in the XML subsystem stanza under test is just to verify that the attributes that accept expressions can be parsed with expressions and that we will get a consistent behaviour preventing that an attribute that currently accepts an expression is not going to change this behavior in future releases.

Just out of curiosity, is there any other reason behind this reasoning?

Right now AbstractSubsystemBaseTest.standardSubsystemTest does not exercise a real expression resolution (as far as I know). I think it could be tricky to make it so generic as to get it under AbstractSubsystemBaseTest without any intervention passing the expected attributes and values from the child class.

@yersan yersan added the ready-for-merge This PR is ready to be merged and fulfills all requirements label Nov 18, 2024
@bstansberry
Copy link
Contributor

Yes, all I'm asking for is that the xml uses expressions. Doing more is fine if people have time but I was not asking for that.

@bstansberry
Copy link
Contributor

@yersan @lvydra Further to this...

Have a look at AttributeDefinition.validateAndSet. It...

  1. Converts the operation param value to ValueExpression if it's an expression and the AD supports it.
  2. Calls validateOperation
  3. Which in turn calls convertToExpectedType.

If the attribute def doesn't support expressions, but the xml uses one and the attribute type is one where an arbitrary string can't convert to the target ModelType, this will fail. So boolean attributes and numerics or complex objects with elements fields like that.

So if someone forgets to support expressions on a string attribute, this won't catch it, but for booleans/numerics it will. The real point of this "best practice" is to encourage devs to mindlessly follow the pattern of using expressions everywhere and thereby hopefully catch mistakes when they use if for things where they forgot to add expression support.

@yersan yersan merged commit 5f7724f into wildfly:main Nov 19, 2024
12 of 13 checks passed
@yersan
Copy link
Collaborator

yersan commented Nov 19, 2024

Thanks @lvydra and @bstansberry for the explanations and review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge This PR is ready to be merged and fulfills all requirements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants