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

[Unified Recorder] Allow passing undefined to sanitizers and other minor changes #19561

Merged

Conversation

HarshaNalluru
Copy link
Member

@HarshaNalluru HarshaNalluru commented Dec 27, 2021

Fixes #19559
Fixes #19560

Changes

  • Allows passing undefined as keys in the sanitizer options so that devs don't have to add additional checks if a certain env variable exists in playback.
  • Exports delay
    • waits for expected time in record/live modes
    • no-op in playback
  • Tests
  • Restructuring tests so that we do not bloat up the files
  • Changelog

@HarshaNalluru HarshaNalluru changed the title [Unified Recorder] Allow passing undefined to sanitizers [Unified Recorder] Allow passing undefined to sanitizers and other minor changes Dec 27, 2021
@HarshaNalluru HarshaNalluru marked this pull request as ready for review December 27, 2021 22:14
sdk/test-utils/recorder-new/src/utils/delay.ts Outdated Show resolved Hide resolved
@@ -97,7 +97,7 @@ export interface RegexSanitizer {
/**
* A regex. Can be defined as a simple regex replace OR if groupForReplace is set, a subsitution operation.
*/
regex: string;
regex?: string;
Copy link
Member

Choose a reason for hiding this comment

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

Is it optional because it is not used in playback mode? if regex is optional, is value optional too?

Copy link
Member Author

@HarshaNalluru HarshaNalluru Dec 27, 2021

Choose a reason for hiding this comment

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

This is only meant for convenience while writing the tests. If regex is undefined, the sanitizer won't be added.

For value, typically it is hard-coded and is a non-null value.
If it turned out to be undefined, it is most likely that the user is doing something wrong/unexpected, hence I didn't think of allowing that.

Co-authored-by: Jeremy Meng <yumeng@microsoft.com>
});

it.skip("ContinuationSanitizer", async () => {
// Skipping since the test is failing in the browser
Copy link
Member Author

Choose a reason for hiding this comment

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

Logged an issue #19572

Copy link
Member

@jeremymeng jeremymeng left a comment

Choose a reason for hiding this comment

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

Looks good to me! I left a couple minor comments

replacers.map((replacer: unknown) =>
this.addSanitizer({
replacers.map((replacer: RegexSanitizer) => {
if (!replacer.regex) return;
Copy link
Member

Choose a reason for hiding this comment

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

should we throw if it's undefined in live/record mode?

Copy link
Member Author

Choose a reason for hiding this comment

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

hmmm, good idea

Copy link
Member Author

Choose a reason for hiding this comment

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

only record mode

fakeConnString: string
): Promise<void> {
if (!actualConnString) return;
Copy link
Member

Choose a reason for hiding this comment

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

should we throw if it's undefined in live/record mode?

Copy link
Member Author

Choose a reason for hiding this comment

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

done
only record mode**

* If the `TEST_MODE` is not `"playback"`, `delay` is a wrapper for setTimeout that resolves a promise after t milliseconds.
*
* @param {number} milliseconds The number of milliseconds to be delayed.
* @returns {Promise<T>} Resolved promise
Copy link
Member

Choose a reason for hiding this comment

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

return type needs update

Copy link
Member Author

Choose a reason for hiding this comment

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

removed

@HarshaNalluru HarshaNalluru merged commit 3891e95 into Azure:main Dec 28, 2021
@HarshaNalluru HarshaNalluru deleted the harshan/pass-undefined-to-santiizers branch December 28, 2021 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants