Skip to content

Ensure that successive calls to HardContext return the same object.#29

Open
josecv wants to merge 1 commit intomasterfrom
josecv/hard-ctx-identity
Open

Ensure that successive calls to HardContext return the same object.#29
josecv wants to merge 1 commit intomasterfrom
josecv/hard-ctx-identity

Conversation

@josecv
Copy link
Copy Markdown
Contributor

@josecv josecv commented Sep 10, 2021

Signed-off-by: Jose Cortes josecortes@datawire.io

Signed-off-by: Jose Cortes <josecortes@datawire.io>
@josecv josecv requested a review from thallgren September 10, 2021 14:59
// If it's already a hard context, just return it as is.
if hardCtx, ok := softCtx.(childHardContext); ok {
return hardCtx
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, because I'd have told you that the above if parentHardCtx == nil case would cover this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, I get it, it's the same type of bug as #26

@LukeShu
Copy link
Copy Markdown
Contributor

LukeShu commented Sep 13, 2021

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.

@LukeShu LukeShu self-requested a review September 13, 2021 18:59
Copy link
Copy Markdown
Contributor

@LukeShu LukeShu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment.

@knlambert knlambert requested review from a team and removed request for a team August 14, 2023 17:04
@thallgren thallgren removed their request for review November 19, 2023 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants