Ensure that successive calls to HardContext return the same object.#29
Open
Ensure that successive calls to HardContext return the same object.#29
Conversation
Signed-off-by: Jose Cortes <josecortes@datawire.io>
LukeShu
reviewed
Sep 13, 2021
| // If it's already a hard context, just return it as is. | ||
| if hardCtx, ok := softCtx.(childHardContext); ok { | ||
| return hardCtx | ||
| } |
Contributor
There was a problem hiding this comment.
I'm confused, because I'd have told you that the above if parentHardCtx == nil case would cover this.
Contributor
There was a problem hiding this comment.
Ohh, I get it, it's the same type of bug as #26
Contributor
|
I agree with the semantics you're going for. But I think your implementation is buggy. If I make the change to your test: diff --git a/dcontext/hardsoft_test.go b/dcontext/hardsoft_test.go
index 90ba569..2ad9d4f 100644
--- a/dcontext/hardsoft_test.go
+++ b/dcontext/hardsoft_test.go
@@ -23,6 +23,7 @@ func TestContextIdentity(t *testing.T) {
if ctx == hardCtx {
t.Fatalf("soft context %+v treated same as hard context %+v", ctx, hardCtx)
}
+ hardCtx = context.WithValue(hardCtx, valkey{}, 0)
if hardCtx != dcontext.HardContext(hardCtx) {
t.Fatalf("hard context %+v treated differently than hard context %+v", hardCtx, dcontext.HardContext(hardCtx))
}then the test fails, and it should not fail. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Signed-off-by: Jose Cortes josecortes@datawire.io