Skip to content

Commit

Permalink
e2e: remove chrome
Browse files Browse the repository at this point in the history
* chromedp has led to flakiness every now and then
* it was used to check that static assets dont return 404
* we can just use regular http GET to do the same check

Signed-off-by: Michael Hoffmann <[email protected]>
  • Loading branch information
Michael Hoffmann committed Dec 17, 2024
1 parent 683cf17 commit 715373b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 55 deletions.
62 changes: 10 additions & 52 deletions test/e2e/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"testing"
"time"

"github.com/chromedp/cdproto/network"
"github.com/chromedp/chromedp"
"github.com/efficientgo/core/testutil"
"github.com/efficientgo/e2e"
e2edb "github.com/efficientgo/e2e/db"
Expand Down Expand Up @@ -367,7 +365,7 @@ func TestQueryExternalPrefixWithoutReverseProxy(t *testing.T) {
WithExternalPrefix(externalPrefix).Init()
testutil.Ok(t, e2e.StartAndWaitReady(q))

checkNetworkRequests(t, "http://"+q.Endpoint("http")+"/"+externalPrefix+"/graph")
checkRequestReturns200(t, "http://"+q.Endpoint("http")+"/"+externalPrefix+"/graph")
}

func TestQueryExternalPrefix(t *testing.T) {
Expand All @@ -388,7 +386,7 @@ func TestQueryExternalPrefix(t *testing.T) {
querierProxy := httptest.NewServer(e2ethanos.NewSingleHostReverseProxy(querierURL, externalPrefix))
t.Cleanup(querierProxy.Close)

checkNetworkRequests(t, querierProxy.URL+"/"+externalPrefix+"/graph")
checkRequestReturns200(t, querierProxy.URL+"/"+externalPrefix+"/graph")
}

func TestQueryExternalPrefixAndRoutePrefix(t *testing.T) {
Expand All @@ -413,7 +411,7 @@ func TestQueryExternalPrefixAndRoutePrefix(t *testing.T) {
querierProxy := httptest.NewServer(e2ethanos.NewSingleHostReverseProxy(querierURL, externalPrefix))
t.Cleanup(querierProxy.Close)

checkNetworkRequests(t, querierProxy.URL+"/"+externalPrefix+"/graph")
checkRequestReturns200(t, querierProxy.URL+"/"+externalPrefix+"/graph")
}

func TestQueryLabelNames(t *testing.T) {
Expand Down Expand Up @@ -1248,59 +1246,19 @@ func TestSidecarQueryEvaluation(t *testing.T) {
}
}

// An emptyCtx is never canceled, has no values, and has no deadline. It is not
// struct{}, since vars of this type must have distinct addresses.
type emptyCtx int

func (*emptyCtx) Deadline() (deadline time.Time, ok bool) {
return
}

func (*emptyCtx) Done() <-chan struct{} {
return nil
}

func (*emptyCtx) Err() error {
return nil
}

func (*emptyCtx) Value(key any) any {
return nil
}

func (e *emptyCtx) String() string {
return "Context"
}

func checkNetworkRequests(t *testing.T, addr string) {
ctx, cancel := chromedp.NewContext(new(emptyCtx))
func checkRequestReturns200(t *testing.T, addr string) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
t.Cleanup(cancel)

testutil.Ok(t, runutil.Retry(1*time.Minute, ctx.Done(), func() error {
var networkErrors []string

// Listen for failed network requests and push them to an array.
chromedp.ListenTarget(ctx, func(ev interface{}) {
switch ev := ev.(type) {
case *network.EventLoadingFailed:
networkErrors = append(networkErrors, ev.ErrorText)
}
})

err := chromedp.Run(ctx,
network.Enable(),
chromedp.Navigate(addr),
chromedp.WaitVisible(`body`),
)

testutil.Ok(t, runutil.Retry(10*time.Second, ctx.Done(), func() error {
resp, err := http.Get(addr)
if err != nil {
return err
}

if len(networkErrors) > 0 {
err = fmt.Errorf("some network requests failed: %s", strings.Join(networkErrors, "; "))
if resp.StatusCode != http.StatusOK {
return errors.Errorf("expected status code 200, got: %d", resp.StatusCode)
}
return err
return nil
}))
}

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/tools_bucket_web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestToolsBucketWebExternalPrefixWithoutReverseProxy(t *testing.T) {
)
testutil.Ok(t, e2e.StartAndWaitReady(b))

checkNetworkRequests(t, "http://"+b.Endpoint("http")+"/"+externalPrefix+"/blocks")
checkRequestReturns200(t, "http://"+b.Endpoint("http")+"/"+externalPrefix+"/blocks")
}

func TestToolsBucketWebExternalPrefix(t *testing.T) {
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestToolsBucketWebExternalPrefix(t *testing.T) {
toolsBucketWebProxy := httptest.NewServer(e2ethanos.NewSingleHostReverseProxy(toolsBucketWebURL, externalPrefix))
t.Cleanup(toolsBucketWebProxy.Close)

checkNetworkRequests(t, toolsBucketWebProxy.URL+"/"+externalPrefix+"/blocks")
checkRequestReturns200(t, toolsBucketWebProxy.URL+"/"+externalPrefix+"/blocks")
}

func TestToolsBucketWebExternalPrefixAndRoutePrefix(t *testing.T) {
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestToolsBucketWebExternalPrefixAndRoutePrefix(t *testing.T) {
toolsBucketWebProxy := httptest.NewServer(e2ethanos.NewSingleHostReverseProxy(toolsBucketWebURL, externalPrefix))
t.Cleanup(toolsBucketWebProxy.Close)

checkNetworkRequests(t, toolsBucketWebProxy.URL+"/"+externalPrefix+"/blocks")
checkRequestReturns200(t, toolsBucketWebProxy.URL+"/"+externalPrefix+"/blocks")
}

func TestToolsBucketWebWithTimeAndRelabelFilter(t *testing.T) {
Expand Down

0 comments on commit 715373b

Please sign in to comment.