-
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
Changes from 5 commits
043a010
5479066
a129f4e
2dc4b43
8bcfe0d
ca84ddf
e402686
da428e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -355,6 +355,75 @@ func TestWithInMemoryProxyAndBackendWithSessions(t *testing.T) { | |
} | ||
} | ||
|
||
func TestProxyTimeout(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
backendHomeDir, err := ioutil.TempDir("", "backend-home") | ||
|
||
if err != nil { | ||
t.Fatalf("Failed to set up a temporary home directory for the test: %v", err) | ||
} | ||
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=10ms", // Use a very short timeout to force a timeout error | ||
|
||
"--request-forwarding-timeout=80s", | ||
"--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) | ||
if !strings.Contains(s, "context deadline exceeded") { | ||
t.Errorf("Timeout should have occurred but didn't") | ||
} | ||
}() | ||
|
||
// 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() | ||
|
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 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.
Done. Using a variable so we can also log the value.