Skip to content

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

Merged
HarshaNalluru merged 14 commits intoAzure:mainfrom
HarshaNalluru:harshan/pass-undefined-to-santiizers
Dec 28, 2021
Merged

[Unified Recorder] Allow passing undefined to sanitizers and other minor changes#19561
HarshaNalluru merged 14 commits intoAzure:mainfrom
HarshaNalluru:harshan/pass-undefined-to-santiizers

Conversation

@HarshaNalluru
Copy link
Copy Markdown
Contributor

@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
Comment thread sdk/test-utils/recorder-new/src/utils/delay.ts Outdated
* A regex. Can be defined as a simple regex replace OR if groupForReplace is set, a subsitution operation.
*/
regex: string;
regex?: string;
Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

only record mode

actualConnString: string | undefined,
fakeConnString: string
): Promise<void> {
if (!actualConnString) return;
Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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

Development

Successfully merging this pull request may close these issues.

[Unified Recorder] Offer delay from recorder to speed up playback [Unified Recorder] Allow passing "undefined" keys to the sanitizers

2 participants