-
Notifications
You must be signed in to change notification settings - Fork 274
test(amazon Q): fix test failure caused by MockTelemetryExtension throwing NotAMockException #5258
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
| <applicationService serviceInterface="migration.software.aws.toolkits.jetbrains.services.telemetry.TelemetryService" | ||
| serviceImplementation="software.aws.toolkits.jetbrains.services.telemetry.DefaultTelemetryService" | ||
| testServiceImplementation="software.aws.toolkits.jetbrains.services.telemetry.NoOpTelemetryService"/> | ||
| serviceImplementation="software.aws.toolkits.jetbrains.services.telemetry.DefaultTelemetryService"/> |
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.
can we keep it as no-op so that tests dont send metrics by default, but you can add the rule if you want to assert metrics?
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.
aha that makes sense
| private val mockTelemetryService: NoOpTelemetryService by lazy { NoOpTelemetryService(publisher, batcher) } | ||
|
|
||
| override fun before() { | ||
| ApplicationManager.getApplication().replaceService(TelemetryService::class.java, mockTelemetryService, mockTelemetryService) |
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.
replaceService needs to be reverted in the after()
|
|
||
| override fun after() { | ||
| reset(batcher()) | ||
| Disposer.dispose(disposableParent) |
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.
@rli is it sufficient for the purpose of reverting replaceService?
…owing NotAMockException (aws#5258) ## Description <!--- Describe your changes in detail --> <!--- If appropriate, providing screenshots will help us review your contribution --> <!--- If there is a related issue, please provide a link here --> Now there are 2 ways to use NoOpTelemetryService 1. if devs are not interested in validating the metric contents, don't need do anything as default test implementation is NoOpTelemetryService 2. if devs are interested in the metric contents, can use `MockTelemetryServiceExtension` which will inject a spy of batcher and replace the original test implementation in junit before hook and revert it in after hook so that you can use ArgumentCaptor to capture what's going through the batcher Relevant aws#5207 ### root cause: Originally by doing `class NoOpTelemetryService : TelemetryService(publisher, spy(DefaultTelemetryBatcher(publisher))) {`, it's not 100% guaranteed that the TelemetryBatcher passed in is a mockito spy, and it result in `NotAMockException` thrown from these cases. ### solution Manually inject spy batcher separately in a different step instead of IDE doing the work when initializing app/project service components--------- Co-authored-by: Richard Li <[email protected]>
Description
Now there are 2 ways to use NoOpTelemetryService
MockTelemetryServiceExtensionwhich will inject a spy of batcher and replace the original test implementation in junit before hook and revert it in after hook so that you can use ArgumentCaptor to capture what's going through the batcherRelevant #5207
root cause:
Originally by doing
class NoOpTelemetryService : TelemetryService(publisher, spy(DefaultTelemetryBatcher(publisher))) {, it's not 100% guaranteed that the TelemetryBatcher passed in is a mockito spy, and it result inNotAMockExceptionthrown from these cases.solution
Manually inject spy batcher separately in a different step instead of IDE doing the work when initializing app/project service components
License
I confirm that my contribution is made under the terms of the Apache 2.0 license.