Skip to content

Commit 78ab866

Browse files
committed
Fix hypeman TLS endpoints and Start cleanup rollback
1 parent 0a56911 commit 78ab866

3 files changed

Lines changed: 51 additions & 6 deletions

File tree

server/e2e/backend_hypeman.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,22 +257,36 @@ func (c *hypemanBackend) Start(ctx context.Context, cfg ContainerConfig) error {
257257
}
258258
c.instanceID = inst.ID
259259

260+
cleanupOnError := func(startErr error) error {
261+
cleanupCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
262+
defer cancel()
263+
if err := c.client.Instances.Delete(cleanupCtx, c.instanceID); err != nil {
264+
return fmt.Errorf("%w (cleanup failed for instance %s: %v)", startErr, c.instanceID, err)
265+
}
266+
c.instanceID = ""
267+
c.ip = ""
268+
return startErr
269+
}
270+
260271
// Wait for the guest program to start. The SDK caps the server-side wait at
261272
// a few minutes; loop until our context deadline if needed.
262273
if err := c.waitForRunning(ctx); err != nil {
263-
return err
274+
return cleanupOnError(err)
264275
}
265276

266277
if c.useIngress {
267278
// Ensure the wildcard ingress rules exist; endpoints derive from the
268279
// instance name + domain, so no instance IP is needed.
269-
return c.ensureIngress(ctx)
280+
if err := c.ensureIngress(ctx); err != nil {
281+
return cleanupOnError(err)
282+
}
283+
return nil
270284
}
271285

272286
// Raw-IP fallback: reach the instance directly on its private network IP.
273287
ip, err := c.resolveIP(ctx)
274288
if err != nil {
275-
return err
289+
return cleanupOnError(err)
276290
}
277291
c.ip = ip
278292
return nil

server/e2e/container.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package e2e
22

33
import (
44
"context"
5+
"net/url"
56
"strings"
67
"testing"
78

@@ -68,12 +69,30 @@ func (c *TestContainer) ChromeDriverURL() string {
6869
// derived from ChromeDriverURL (without scheme). Useful for substring assertions
6970
// on proxy-rewritten URLs.
7071
func (c *TestContainer) ChromeDriverAddr() string {
71-
return strings.TrimPrefix(c.backend.ChromeDriverURL(), "http://")
72+
u, err := url.Parse(c.backend.ChromeDriverURL())
73+
if err == nil && u.Host != "" {
74+
return u.Host
75+
}
76+
77+
addr := strings.TrimPrefix(c.backend.ChromeDriverURL(), "http://")
78+
return strings.TrimPrefix(addr, "https://")
7279
}
7380

7481
// ChromeDriverWSURL returns the WebSocket URL (ws://host:port/path) for the
7582
// instance's ChromeDriver proxy. path should include a leading slash.
7683
func (c *TestContainer) ChromeDriverWSURL(path string) string {
84+
u, err := url.Parse(c.backend.ChromeDriverURL())
85+
if err == nil && u.Host != "" {
86+
if u.Scheme == "https" {
87+
u.Scheme = "wss"
88+
} else {
89+
u.Scheme = "ws"
90+
}
91+
u.Path = path
92+
u.RawQuery = ""
93+
u.Fragment = ""
94+
return u.String()
95+
}
7796
return "ws://" + c.ChromeDriverAddr() + path
7897
}
7998

server/e2e/e2e_cdp_reconnect_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,20 @@ func touchContainerFile(ctx context.Context, client *instanceoapi.ClientWithResp
456456
}
457457

458458
func fetchBrowserWebSocketURL(ctx context.Context, c *TestContainer) (string, error) {
459-
versionURL := fmt.Sprintf("http://%s/json/version", c.CDPAddr())
460-
req, err := http.NewRequestWithContext(ctx, http.MethodGet, versionURL, nil)
459+
versionURL, err := url.Parse(c.CDPURL())
460+
if err != nil {
461+
return "", err
462+
}
463+
if versionURL.Scheme == "wss" {
464+
versionURL.Scheme = "https"
465+
} else {
466+
versionURL.Scheme = "http"
467+
}
468+
versionURL.Path = "/json/version"
469+
versionURL.RawQuery = ""
470+
versionURL.Fragment = ""
471+
472+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, versionURL.String(), nil)
461473
if err != nil {
462474
return "", err
463475
}

0 commit comments

Comments
 (0)