-
Notifications
You must be signed in to change notification settings - Fork 1
Pass app-lifetime context to controller, orchestrator, repomanager #115
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // Copyright (c) 2026 Uber Technologies, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package controller | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| orchestratormock "github.com/uber/tango/orchestrator/orchestratormock" | ||
| "go.uber.org/mock/gomock" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| // TestNewController_StoresAppContext verifies the caller-supplied context is | ||
| // retained and is the one observed by background goroutines. | ||
| func TestNewController_StoresAppContext(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| appCtx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
|
|
||
| c := NewController(appCtx, Params{ | ||
| Logger: zap.NewNop(), | ||
| Orchestrator: orchestratormock.NewMockOrchestrator(ctrl), | ||
| }).(*controller) | ||
|
|
||
| assert.Same(t, appCtx, c.appCtx) | ||
| assert.NoError(t, c.appCtx.Err()) | ||
|
|
||
| cancel() | ||
| assert.ErrorIs(t, c.appCtx.Err(), context.Canceled) | ||
| } | ||
|
|
||
| // TestLinkRequestCtx_CancelsOnAppCtx verifies that the linked context is | ||
| // cancelled when the controller's appCtx is cancelled, even if the request | ||
| // context is still live. | ||
| func TestLinkRequestCtx_CancelsOnAppCtx(t *testing.T) { | ||
| appCtx, cancelApp := context.WithCancel(context.Background()) | ||
| defer cancelApp() | ||
| c := &controller{appCtx: appCtx} | ||
|
|
||
| reqCtx, cancelReq := context.WithCancel(context.Background()) | ||
| defer cancelReq() | ||
|
|
||
| linked, cancelLink := c.linkRequestCtx(reqCtx) | ||
| defer cancelLink() | ||
| assert.NoError(t, linked.Err()) | ||
|
|
||
| cancelApp() | ||
| <-linked.Done() | ||
| assert.ErrorIs(t, linked.Err(), context.Canceled) | ||
| assert.NoError(t, reqCtx.Err(), "linkRequestCtx must not cancel the request ctx") | ||
| } | ||
|
|
||
| // TestLinkRequestCtx_CancelsOnRequestCtx verifies that cancellation of the | ||
| // request context propagates to the linked context. | ||
| func TestLinkRequestCtx_CancelsOnRequestCtx(t *testing.T) { | ||
| appCtx, cancelApp := context.WithCancel(context.Background()) | ||
| defer cancelApp() | ||
| c := &controller{appCtx: appCtx} | ||
|
|
||
| reqCtx, cancelReq := context.WithCancel(context.Background()) | ||
| linked, cancelLink := c.linkRequestCtx(reqCtx) | ||
| defer cancelLink() | ||
| assert.NoError(t, linked.Err()) | ||
|
|
||
| cancelReq() | ||
| <-linked.Done() | ||
| assert.ErrorIs(t, linked.Err(), context.Canceled) | ||
| assert.NoError(t, appCtx.Err(), "linkRequestCtx must not cancel the app ctx") | ||
| } | ||
|
|
||
| // TestLinkRequestCtx_CancelReleasesAfterFunc verifies that calling the returned | ||
| // cancel func stops the appCtx watcher so cancelling appCtx afterwards does | ||
| // not affect the now-detached linked context. | ||
| func TestLinkRequestCtx_CancelReleasesAfterFunc(t *testing.T) { | ||
| appCtx, cancelApp := context.WithCancel(context.Background()) | ||
| defer cancelApp() | ||
| c := &controller{appCtx: appCtx} | ||
|
|
||
| linked, cancelLink := c.linkRequestCtx(context.Background()) | ||
| cancelLink() | ||
| <-linked.Done() | ||
| firstErr := linked.Err() | ||
| assert.ErrorIs(t, firstErr, context.Canceled) | ||
|
|
||
| // Cancelling appCtx after the linked ctx is already cancelled must be a | ||
| // no-op (the AfterFunc handle should have been released by cancelLink). | ||
| cancelApp() | ||
| assert.Equal(t, firstErr, linked.Err(), "linked.Err() must not change after cancelLink") | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
the context here should be detached from existing one, so that when c.appctx is cancelled, the upload still continues on best effort
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.
App context is cancelled when application shuts down as it is signalled by the host management platform. SIGKILL is very likely to follow soon after. How should "best effort" look like in this case?
Uh oh!
There was an error while loading. Please reload this page.
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.
I'm thinking best effort of uploading results to survive both client disconnect and app shutdown -- nothing cancels it, upload whatever it can.
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 are few severe anti-patterns in this decision as I see of.
https://dave.cheney.net/2016/12/22/never-start-a-goroutine-without-knowing-how-it-will-stop