-
Notifications
You must be signed in to change notification settings - Fork 35
Add unit tests for main.go and handle APM server edge behaviors #136
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
b16af4a
to
4b84052
Compare
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.
This is really great, thanks for building this test framework! I'm just wondering if there's some way we can add an assertion to the tests or if it makes sense to have the absence of a panic indicate that the test passes.
// Flush any APM data, in case waiting for the agentDone or runtimeDone signals | ||
// timed out, the agent data wasn't available yet, and we got to the next non-shutdown event | ||
extension.FlushAPMData(client, agentDataChannel, config) | ||
|
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.
Why did you move this block to after the Shutdown event check?
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.
When writing my tests, I found myself in the following situation :
Test setup :
- APM Server configured to be very slow (approx 3 seconds to respond).
- APM Agent Data channel filled with data
- SendStrategy configured to background
Behavior :
The extension starts sending data from the loaded channel to the slow APM server. It is then interrupted due to the current event being finished. A shutdown event is then received, and we start flushing APM data. The issue is that this takes a tremendous time if the APM Agent data channel is full and if the response time of the Server is large, even if the SendStrategy is set to background
.
An alternative solution would be to put the flush statement above the Shutdown, but to only run FlushAPMData
if the SendStrategy is SyncFlush
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.
Thanks for the explanation. I think we might want to remove this flush anyway: with syncFlush
, we'll flush at the end of an invocation so there won't be anything to flush upon a new function invocation. With background
, we'll just continue receiving from the channel in the go routine when the extension starts its work for a new function invocation.
Regarding success/failure assertions, it really depends on the specific test. Explicitly stating an assertion for each test will increase clarity, even if it is just the absence of panic. I will make a proposal for each of them. |
I added success/failure assertions in 41a8039. For most tests, I check if the extension does not panic and if APM data is correctly sent to the APM server. |
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.
👍🏼
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.
Just two minor comments then I think we can merge this. Thanks for your work on this!
Motivation
The goal of these tests is to ease the refactor of the extension following the recent code reviews. They can also be used to solve some of the current issues. For example :
TestFlush
reproduces "panic: send on closed channel" from the extension #133 (aRuntimeDone
signal is sent to the extension after the closure of the channel)TestSeveralTransactions
reproduces panic: sync: WaitGroup is reused before previous Wait has returned #128 (race condition causing aWaitGroup
to be modified while it hangs)The core idea is to combine a mock Lambda API backend with a mock APM server to enable the recreation of several scenarios.
Limitations
TestFlush
panics. Same forTestSeveralTransactions
, as the related issue is not yet solved.