-
Notifications
You must be signed in to change notification settings - Fork 358
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
Refactor TestResult into proper rusty result type #1827
Conversation
Signed-off-by: yihuaf <[email protected]>
Signed-off-by: yihuaf <[email protected]>
My memory escapes me a little here, but I thought the reasoning behind the idea of skipping tests was to not consider them failures if the system the tests are run on isn't capable of running that test. Is it appropriate to consider it an error type? To me it doesn't really seem like an error, though I could see benefits in the future if we ever want to include context as to why a certain test got skipped. |
Logically, yes, Also, I think the key thing here is not get hangup on the case of what is an error. Rather, my mental model is that the result type is a list of explicit Enum or state where the Ok state is specially handled. All other state are grouped together and handled. |
Signed-off-by: yihuaf <[email protected]>
Hey, I'll take a look at this over weekend 👍 |
Hye @yihuaf , thanks a lot for putting in the time and making this PR. One thing is you have added a Unfortunately, I don't particularly get the reasoning/advantages behind this. I think introduction of thiserror might be a good idea, but I didn't see changes in output of my failing tests. Some points which makes me question the changes here :
Thus we need something that is capable of indicating these three different states. Putting these in rust's Result does not do any good, because we still have to do a match with three arms (Ok, err(skipped), err(failed) ); moreover now we must consider skipped as either failure (as in this PR) or passing , both of which are not really correct. I might be missing something that you see, and maybe the changes you have proposed might have benefits which I do not see yet. However, I don't currently see tradeoff of changing to more rusty Result v/s the points I mentioned above being worth it. Please feel free to correct me or indicate the reasons I am missing. |
The main motivation for the change is that in lifecycle tests, the test itself calls other tests. Without using
Exactly. The key here is should we allow test cases to call other test cases?
This is not true. Yes, most test case will return
I agree that
Lastly, I kept In the end, I don't feel strongly about this particular implementation, but I would like to at least go with this direction or refactor other test cases to avoid the test case calling other test case situation. |
I've thought a bit more about this and I believe the core of the issue is test cases calling other test cases. I am now more inclined to refactor the tests such that we do not call other test cases within a test case directly. In addition, in this case, the @YJDoc2 Let me know what you think. |
@YJDoc2 Let me what you think :) ? I read the lifecycle test again and I think the issue I previously described is mostly focused within the lifecycle test. The other tests are much more simpler and straightforward. I think a better approach is to refactor the lifecycle tests to not use TestResult if a function call is used within the lifecycle test. We can decide what we should do with TestResult at a later point? |
@yihuaf Apologies for late reply, I was a bit busy, and missed this 😓 So I agree with you that we should not be calling tests inside other tests as if util functions. So We should make the lifecycle functions "util" functions , which return normal Rust results, and other tests will call them as normal functions. The lifecycle tests themselves will also simply call these functions and convert their result into TestResult (at least for now). I feel it would be a better approach to first do this refactoring and then maybe take another look at what this PR aims to do, maybe we will get a better idea of exactly what needs to be changed. Separating out lifecycle stuff as normal functions is definitely something that we should go ahead with 👍 On a separate note,
I'm not sure exactly which test you are talking about, but the Again, apologies for late reply, thanks for pinging me again! |
No worries :)
You understood it correctly. I was talking in the context of test calling other test. I agree with your assessment on this.
I agree. I will close this PR and open a new PR for this change. I am glad we talked/sorted this out :) |
This PR refactored the
TestResult
into a rustystd::Result<T, TestError>
. In this way, the handling ofTestResult
can follow how rust handles error, such as using?
. We further usethiserror
to generate properTestError
for the cases theTestResult
was handling. For simplicity, we wrapTestError::Failed
withanyhow::Error
to maintain backward compatibility. In the future, we can, should, and will expand the TestError::Failed case to specific errors so the error handling can become more explicit.Tag along, also enabled container
exec
test since it is implemented now.