Skip to content

Commit be7864a

Browse files
committed
fix tests
1 parent c49c5e1 commit be7864a

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

pkg/transport/proxy/transparent/transparent_proxy.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ func (p *TransparentProxy) monitorHealth(parentCtx context.Context) {
151151
ticker := time.NewTicker(10 * time.Second)
152152
defer ticker.Stop()
153153

154+
var failCount int
155+
const maxFails = 5
156+
154157
for {
155158
select {
156159
case <-parentCtx.Done():
@@ -162,11 +165,21 @@ func (p *TransparentProxy) monitorHealth(parentCtx context.Context) {
162165
case <-ticker.C:
163166
alive := p.healthChecker.CheckHealth(parentCtx)
164167
if alive.Status != healthcheck.StatusHealthy {
165-
logger.Infof("Health check failed for %s; initiating proxy shutdown", p.containerName)
166-
if err := p.Stop(parentCtx); err != nil {
167-
logger.Errorf("Failed to stop proxy for %s: %v", p.containerName, err)
168+
failCount++
169+
logger.Warnf("Health check %d/%d failed for %s", failCount, maxFails, p.containerName)
170+
if failCount >= maxFails {
171+
logger.Infof("Health check failed %d times; shutting down proxy for %s", maxFails, p.containerName)
172+
if err := p.Stop(parentCtx); err != nil {
173+
logger.Errorf("Failed to stop proxy for %s: %v", p.containerName, err)
174+
}
175+
return
176+
}
177+
} else {
178+
// Reset counter on success
179+
if failCount > 0 {
180+
logger.Infof("Health check recovered for %s; resetting failure counter", p.containerName)
168181
}
169-
return
182+
failCount = 0
170183
}
171184
}
172185
}

pkg/workloads/manager.go

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,11 @@ func (*defaultManager) RunWorkloadDetached(runConfig *runner.RunConfig) error {
360360
var stderrWriter io.Writer
361361
if logFile != nil {
362362
detachedCmd.Stdout = logFile
363-
stderrWriter = io.MultiWriter(logFile)
363+
stderrWriter = io.MultiWriter(logFile, os.Stderr)
364364
} else {
365365
// Otherwise, discard the output
366-
stderrWriter = io.Discard
367-
detachedCmd.Stdout = nil
366+
detachedCmd.Stdout = io.Discard
367+
stderrWriter = os.Stderr
368368
}
369369

370370
if err := detachedCmd.Start(); err != nil {
@@ -379,31 +379,20 @@ func (*defaultManager) RunWorkloadDetached(runConfig *runner.RunConfig) error {
379379

380380
stderrCh := make(chan string, 1)
381381
go func() {
382-
buf := &bytes.Buffer{}
383-
_, err = io.Copy(buf, stderrPipe)
384-
if err != nil {
385-
logger.Warnf("Warning: Failed to read stderr: %v", err)
386-
stderrCh <- ""
387-
return
388-
}
389-
390-
_, err = stderrWriter.Write(buf.Bytes())
391-
if err != nil {
392-
logger.Warnf("Warning: Failed to write stderr to log file: %v", err)
393-
stderrCh <- ""
394-
}
395-
382+
buf := new(bytes.Buffer)
383+
io.Copy(buf, stderrPipe)
384+
stderrWriter.Write(buf.Bytes()) // log the raw stderr once
396385
stderrCh <- buf.String()
397386
}()
398387

399388
select {
400-
case out := <-stderrCh:
401-
if out != "" {
402-
return fmt.Errorf("startup error (PID %d): %s", pid, out)
389+
case errOut := <-stderrCh:
390+
if errOut != "" {
391+
return nil // no error, just output
403392
}
404393
case <-time.After(2 * time.Second):
394+
// no immediate error
405395
}
406-
407396
logger.Infof("MCP server is running in the background (PID: %d)", detachedCmd.Process.Pid)
408397
logger.Infof("Use 'thv stop %s' to stop the server", runConfig.ContainerName)
409398

test/e2e/proxy_oauth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ var _ = Describe("Proxy OAuth Authentication E2E", Serial, func() {
443443

444444
By("Reconnecting via MCP to trigger token refresh")
445445
proxyURL := fmt.Sprintf("http://localhost:%d/sse", proxyPort)
446-
err = e2e.WaitForMCPServerReady(config, proxyURL, "sse", 10*time.Second)
446+
err = e2e.WaitForMCPServerReady(config, proxyURL, "sse", 30*time.Second)
447447
Expect(err).ToNot(HaveOccurred(), "MCP server not ready after token expiry")
448448

449449
mcpClient, err := e2e.NewMCPClientForSSE(config, proxyURL)

0 commit comments

Comments
 (0)