-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Safer formatting of Xunit assertion messages #7446
Conversation
a141a33
to
208c05e
Compare
Thanks @milang , I was about to create a PR but I saw that you had already done one. |
This is a racy spec - there's a bunch of timing-sensitive ones in the Akka.Streams test suite that have this problem. Issue is not caused by your PR |
I'll need to re-run this and see what's going on here - test didn't get "reported" as failed by AzDo for some reason, but I could find this in the logs. |
I removed serialization from |
Let's go ahead and keep it just because I don't know what the secondary effects are of removing it |
f213199
to
e93440b
Compare
I restored the |
Thank you @milang ! |
Fixes #7442
Changes
This pull request updates
Akka.TestKit.XUnit2
to format assertion messages withstring.Format
only when formatting arguments are specified, otherwise it uses format string as-is. For more background/motivation, please see akkadotnet/Akka.TestKit.NUnit#159.Additionally, this PR adds a new project,
src/contrib/testkits/Akka.TestKit.Xunit2.Tests
. This project contains tests that verify formatting behavior.This PR also refactors the existing
AkkaEqualException
class. Instead of deferring assertion message creation/formatting untilMessage
property call (as originally implemented), the updated code builds the message at the time exception instance is created, and stores the value in base class'Message
property. This allows us to remove_format
+_args
fields and theMessage
property override, simplifying the class.Please note that I also fixed the
protected AkkaEqualException(SerializationInfo info, StreamingContext context)
deserialization constructor that was implemented incorrectly + markedAkkaEqualException
as[Serializable]
+ added a testAkkaEqualExceptionSpec.Constructor_deserializes_message
to verify the serialization/deserialization roundtrip preserves the most important part of the exception instance,Message
. I personally recommend removing the constructor altogether, as the base classXunitException
does not implement deserialization constructor at all, plus the binary formatter is obsolete as of .NET 8+ (Microsoft announcement).Important
@Aaronontheweb please let me know if you would like me to remove the constructor as part of this PR.
Checklist
For significant changes, please ensure that the following have been completed (delete if not relevant):