-
Notifications
You must be signed in to change notification settings - Fork 79
Support a separate timeout for listing pending requests #149
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 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
043a010
Support a custom list-pending-requests timeout
kenfreeman 5479066
Revert "Support a custom list-pending-requests timeout"
kenfreeman a129f4e
Support a custom list-pending-requests timeout
kenfreeman 2dc4b43
Support a custom list-pending-requests timeout
kenfreeman 8bcfe0d
Support a custom list-pending-requests timeout
kenfreeman ca84ddf
Support a custom list-pending-requests timeout
kenfreeman e402686
Support a custom list-pending-requests timeout
kenfreeman da428e5
Support a custom list-pending-requests timeout
kenfreeman 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -355,6 +355,92 @@ func TestWithInMemoryProxyAndBackendWithSessions(t *testing.T) { | |
} | ||
} | ||
|
||
func TestProxyTimeout(t *testing.T) { | ||
// First test with a short timeout to ensure we get timeouts | ||
proxyTimeout := "10ms" | ||
requestForwardingTimeout := "60s" | ||
wantTimeout := true | ||
|
||
// Run the test many times to guard against flakiness | ||
for i := 0; i < 20; i++ { | ||
timeoutTest(t, proxyTimeout, requestForwardingTimeout, wantTimeout) | ||
} | ||
|
||
// Now test with a long-ish timeout to ensure we don't get timeouts | ||
|
||
proxyTimeout = "60s" | ||
wantTimeout = false | ||
for i := 0; i < 20; i++ { | ||
timeoutTest(t, proxyTimeout, requestForwardingTimeout, wantTimeout) | ||
} | ||
} | ||
|
||
func timeoutTest(t *testing.T, proxyTimeout string, requestForwardingTimeout string, wantTimeout bool) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
backendHomeDir := filepath.Join(t.TempDir(), "backend-home") | ||
gcloudCfg := filepath.Join(backendHomeDir, ".config", "gcloud") | ||
if err := os.MkdirAll(gcloudCfg, os.ModePerm); err != nil { | ||
t.Fatalf("Failed to set up a temporary home directory for the test: %v", err) | ||
} | ||
backendURL := RunBackend(ctx, t) | ||
fakeMetadataURL := RunFakeMetadataServer(ctx, t) | ||
|
||
parsedBackendURL, err := url.Parse(backendURL) | ||
if err != nil { | ||
t.Fatalf("Failed to parse the backend URL: %v", err) | ||
} | ||
proxyPort, err := RunLocalProxy(ctx, t) | ||
proxyURL := fmt.Sprintf("http://localhost:%d", proxyPort) | ||
if err != nil { | ||
t.Fatalf("Failed to run the local inverting proxy: %v", err) | ||
} | ||
t.Logf("Started backend at localhost:%s and proxy at %s", parsedBackendURL.Port(), proxyURL) | ||
|
||
// This assumes that "Make build" has been run | ||
args := strings.Join(append( | ||
[]string{"${GOPATH}/bin/proxy-forwarding-agent"}, | ||
"--backend=testBackend", | ||
"--proxy", proxyURL+"/", | ||
"--proxy-timeout="+proxyTimeout, | ||
"--request-forwarding-timeout="+requestForwardingTimeout, | ||
"--host=localhost:"+parsedBackendURL.Port()), | ||
" ") | ||
agentCmd := exec.CommandContext(ctx, "/bin/bash", "-c", args) | ||
|
||
var out bytes.Buffer | ||
agentCmd.Stdout = &out | ||
agentCmd.Stderr = &out | ||
agentCmd.Env = append(os.Environ(), "PATH=", "HOME="+backendHomeDir, "GCE_METADATA_HOST="+strings.TrimPrefix(fakeMetadataURL, "http://")) | ||
if err := agentCmd.Start(); err != nil { | ||
t.Fatalf("Failed to start the agent binary: %v", err) | ||
} | ||
defer func() { | ||
cancel() | ||
err := agentCmd.Wait() | ||
|
||
s := out.String() | ||
t.Logf("Agent result: %v, stdout/stderr: %q", err, s) | ||
timeoutOccurred := strings.Contains(s, "context deadline exceeded") | ||
if timeoutOccurred != wantTimeout { | ||
t.Errorf("Unexpected timeout state: got %v, want %v", timeoutOccurred, wantTimeout) | ||
} | ||
}() | ||
|
||
// Send one request through the proxy to make sure the agent has come up. | ||
// | ||
// We give this initial request a long time to complete, as the agent takes | ||
// a long time to start up. | ||
testPath := "/some/request/path" | ||
if err := checkRequest(proxyURL, testPath, testPath, time.Second, backendCookie); err != nil { | ||
t.Fatalf("Failed to send the initial request: %v", err) | ||
} | ||
|
||
if err := checkRequest(proxyURL, testPath, testPath, 100*time.Millisecond, backendCookie); err != nil { | ||
t.Fatalf("Failed to send request %v", err) | ||
} | ||
} | ||
|
||
func TestGracefulShutdown(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
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
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.
I don't think we should be doing this within the test itself.
Running a test multiple times is better done just using the
--count
flag togo test
.Moreover, I don't think running in a loop would reduce flakiness; it would make any failure in any iteration cause the entire test to fail.
That seems like it would exacerbate any potential sources of flakiness rather than minimizing them.
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.
Removed the loop