-
Notifications
You must be signed in to change notification settings - Fork 735
fix(cwl): Dispose event listeners when command exits #6095
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
Conversation
|
| groupName: testLogGroup, | ||
| regionName: testRegion, | ||
| }) | ||
| await new Promise((r) => setTimeout(r, 500)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of doing a sleep can we do a waitUntil something happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, TailLogGroup doesn't expose anything that we can wait on that tells us that we have done the work required to do our test assertions.
We could possibly emit an event each time the command processes a new Stream frame. Then in the test we would waitUntil the event is emitted X times.
So far the actual feature hasn't required that, but I can look into adding that for test purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was able to use waitUntil by waiting on the LiveTailRegistry to see when there's a session in there (signals session started).
Then we can wait until the content in the document matches the expected. This is does both: validating the content of the doc, and waiting until the stream is fully processed.
|
Accident closed while trying to update my local feature branch against the remote branch. |
| let clock: FakeTimers.InstalledClock | ||
|
|
||
| before(function () { | ||
| clock = installFakeClock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using fake clocks is screwing with the waitUntil() calls. Inspecting the test that uses the clock: the assertions made against the fake clock is a functionality of LiveTailSession.closeSession(), and not TailLogGroup. If we want to assert that the timer is disposed of, it should be done in those unit tests, and not here.
Removing the clock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed: #6110
…ject. (#6110) ## Problem The `LiveTailSession` object's start/stop methods aren't directly under test. TailLogGroup tests are mocking their behavior. TailLogGroup command tests are more focused on managing the session registry, opening/writing to the document, and the close tab behaviors. ## Solution Write a test that's scoped to creating a `session` and calling start and stop on it. Assert that timers are handled/disposed of properly, and that the session response stream is returned. Addresses [this comment](#6095 (comment)). --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Keegan Irby <[email protected]>
## Problem TailLogGroup command is not being fully cleaned up properly. The event listeners for: * showing the StatusBar item * closing a session when exiting its editors are not being disposed of. As users stop sessions, these listeners remain active whilst doing no meaningful work. This is effectively a memory leak. Additionally during testing, I noticed that we are adding a session to the LiveTailRegistry before the session is actually started. This could cause an issue where a session stream isn't successfully created, but the session is still registered. ## Solution * Create an array of disposables and dispose of them as we exit the TailLogGroup command * Only register a session after startLiveTail returns Because now we dispose of the "tab close" listener when tailLogGroup exits, changes are needed in the unit tests to keep the mock response stream "open" as the test executes. This keeps tailLogGroup from returning/disposing while we perform test assertions and close the editors.
…ject. (aws#6110) ## Problem The `LiveTailSession` object's start/stop methods aren't directly under test. TailLogGroup tests are mocking their behavior. TailLogGroup command tests are more focused on managing the session registry, opening/writing to the document, and the close tab behaviors. ## Solution Write a test that's scoped to creating a `session` and calling start and stop on it. Assert that timers are handled/disposed of properly, and that the session response stream is returned. Addresses [this comment](aws#6095 (comment)). --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Keegan Irby <[email protected]>
Problem
TailLogGroup command is not being fully cleaned up properly. The event listeners for:
are not being disposed of. As users stop sessions, these listeners remain active whilst doing no meaningful work. This is effectively a memory leak.
Additionally during testing, I noticed that we are adding a session to the LiveTailRegistry before the session is actually started. This could cause an issue where a session stream isn't successfully created, but the session is still registered.
Solution
Because now we dispose of the "tab close" listener when tailLogGroup exits, changes are needed in the unit tests to keep the mock response stream "open" as the test executes. This keeps tailLogGroup from returning/disposing while we perform test assertions and close the editors.
License: I confirm that my contribution is made under the terms of the Apache 2.0 license.