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

Refactor all tests that use LitJson to use System Text Json #3618

Open
wants to merge 1 commit into
base: petesong/stj-2
Choose a base branch
from

Conversation

peterrsongg
Copy link
Contributor

Description

This updates all tests to use system.text.json so that we can eventually remove the litJSON dependency. System.Text.JSON is much more strict on what it can parse, so I had to add a SanitizeJson method that sanitizes the jsonstring before trying to parse so that the tests don't blow up. I also had found 2 issues with the event stream tests in core. One is that the test was previously looking for header as the json property name when it should've been looking for headers, because of this none of the asserts were actually being triggered. After changing that I uncovered a bug in the Byte header, where the test was sending back a signed byte but we were expecting it to be an unsigned byte. I plan to fix this in an upcoming PR b/c it doesn't seem like a simple fix.

Motivation and Context

Eventual removal of LitJSON as a dependency.

Testing

Dry run passes, also manually stepped through each changed test to make sure it was running as expected. By doing this I found 2 issues with event stream tests as described in the description.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

@peterrsongg peterrsongg force-pushed the petesong/stj-refactor-tests branch from 9aa866f to 1412082 Compare January 24, 2025 19:29
@peterrsongg peterrsongg changed the base branch from petesong/stj to petesong/stj-2 January 27, 2025 21:08
// if we catch ane exception
catch (JsonException)
{
santizedMessageText = JsonSerializerHelper.SanitizeJson(messageText);
Copy link
Contributor

Choose a reason for hiding this comment

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

How bad of a performance hit is the SanitizeJson? It already tried to parse it once, then gets a regex performance hit, before another performance hit trying to parse it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't measure the performance hit, but without the sanitize, the parsing of the message will just fail if the json is invalid. My way of guarding against this potential performance reqression every time was to do the try catch so that we only sanitize if we fail. I believe I put this in here b/c there was a failing test without it, but let me double check to see if I can remove it and the test passes. If so, I will just remove it here but if not maybe the test itself needs to be looked at again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up just fixing the test case which was missing a comma, and removing the sanitize call here. Since the json will come from the service, we shouldn't have to sanitize the message.

@peterrsongg peterrsongg changed the base branch from petesong/stj-2 to v4-development January 28, 2025 18:54
@peterrsongg peterrsongg changed the base branch from v4-development to petesong/stj-2 January 28, 2025 18:55
@peterrsongg peterrsongg force-pushed the petesong/stj-refactor-tests branch from bd2a8a8 to 135f89d Compare January 31, 2025 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants