-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add deep copy for consumers #86
Add deep copy for consumers #86
Conversation
16bbb5e
to
2069a0f
Compare
9b0b5d3
to
daae825
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.
Overall this LGTM modulo two places where the original object is modified in Copy
methods. Also, I think it would be good if we have some unit tests for better coverage and guard against the the typos.
annotation/consume_trigger.go
Outdated
copyConsumer := *t | ||
t.Ann = t.Ann.copy() |
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.
copyConsumer := *t | |
t.Ann = t.Ann.copy() | |
copyConsumer := *t | |
copyConsumer.Ann = t.Ann.copy() |
Right? it's a bit strange for a Copy
method to return the original Ann
and then modify the receiver's Ann
.
Can we also add some unit tests (with the help of reflection) to guard against such cases?
The idea I think would be to use cmp.Diff
to check the copied objects are deeply equal, and then use reflections to check (1) the pointer fields in the old and new objects are different, and (2) the old objects are not modified (perhaps by comparing them to another copy made by reflect.Copy
).
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.
Good catch! Although not affecting the functionality, this was definitely a type that deserved fixing. You are right, we should unit tests to catch such inadvertent mistakes. Added unit tests for the same under copy_test
.
annotation/consume_trigger.go
Outdated
copyConsumer := *t | ||
t.Ann = t.Ann.copy() |
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.
Same as the above here :)
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.
(same as above. Fixed and added unit test to safeguard :) )
337055f
to
019ced5
Compare
2069a0f
to
bba340e
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## sonalmahajan15/revamp-producer-consumer #86 +/- ##
===========================================================================
- Coverage 89.29% 89.18% -0.11%
===========================================================================
Files 54 55 +1
Lines 8688 9156 +468
===========================================================================
+ Hits 7758 8166 +408
- Misses 774 825 +51
- Partials 156 165 +9 ☔ View full report in Codecov by Sentry. |
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.
LGTM apart from one comment to separate the test utility stuff to a separate package for easier maintenance.
I think the test utilities here are general and complex enough to warrant being put in a separate test utility package (which is also what stdlib does), but that can definitely be in a separate follow-up PR.
|
||
type CopyTestSuite struct { | ||
suite.Suite | ||
initStructs []any |
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.
We can probably make this a generic struct with a type constraint on having Copy
method to remove some boilerplate code below.
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.
Created issue #172 to perform this refactoring in a follow-up PR.
// limitations under the License. | ||
|
||
package annotation | ||
|
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.
A continuation of the comment made to previous PR: after seeing this, I think we might be more incentivized to move the test utility stuff to a separate package (say, internal/nilawaytest
) for easier maintenance.
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.
Created issue #172 to perform this refactoring in a follow-up PR.
019ced5
to
06ebb58
Compare
bba340e
to
1c8d6f6
Compare
06ebb58
to
9534584
Compare
1c8d6f6
to
7614ccb
Compare
9534584
to
c7b4d03
Compare
7614ccb
to
d97e64e
Compare
c7b4d03
to
35156bd
Compare
d97e64e
to
650ff29
Compare
35156bd
to
6814686
Compare
650ff29
to
a1668d2
Compare
This PR refines the error message by incorporating information about the assignments. Following is an example of an informative error message: Code snippet: ``` func test(x *int) { x = nil y := x z := y print(*z) } ``` Error message: ``` Potential nil panic detected. Observed nil flow from source to dereference point: -> errormessage/errormessage.go:32:9: literal `nil` dereferenced via the assignment(s): -> `nil` to `x` at errormessage/errormessage.go:29:2, -> `x` to `y` at errormessage/errormessage.go:30:2, -> `y` to `z` at errormessage/errormessage.go:31:2 ``` [closes #83 ] [depends on #86 ]
b2995c6
into
sonalmahajan15/revamp-producer-consumer
This PR modifies the consumers to add support for deep copy when the consumers are being copied in backpropagation.
[depends on #80 ]