Skip to content

Commit

Permalink
fix flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Jul 8, 2024
1 parent 5ad4b5a commit c42b414
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion element_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func TestIframeCrossDomains(t *testing.T) {
<iframe sandbox src="`+u1+`"></iframe>
</html>`)

u := launcher.New().HeadlessNew(true).MustLaunch()
u := launcher.New().HeadlessNew(true).NoSandbox(true).MustLaunch()
browser := rod.New().ControlURL(u).NoDefaultDevice().MustConnect()
defer browser.MustClose()

Expand Down
6 changes: 3 additions & 3 deletions hijack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestHijackMockWholeResponse(t *testing.T) {

go router.Run()

g.page.MustNavigate("http://test.com")
g.page.MustNavigate("http://localhost")

g.Eq("ok", g.page.MustElement("body").MustText())
}
Expand Down Expand Up @@ -289,7 +289,7 @@ func TestHijackLoadResponseErr(t *testing.T) {
wg := &sync.WaitGroup{}
wg.Add(1)

router.MustAdd("http://test.com/a", func(ctx *rod.Hijack) {
router.MustAdd("http://localhost/a", func(ctx *rod.Hijack) {
g.Err(ctx.LoadResponse(&http.Client{
Transport: &MockRoundTripper{err: errors.New("err")},
}, true))
Expand All @@ -308,7 +308,7 @@ func TestHijackLoadResponseErr(t *testing.T) {

go router.Run()

_ = p.Navigate("http://test.com/a")
_ = p.Navigate("http://localhost/a")

wg.Wait()
}
Expand Down
1 change: 1 addition & 0 deletions lib/launcher/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (lc *Browser) Validate() error {
}

cmd := exec.Command(lc.BinPath(), "--headless", "--no-sandbox",
"--use-mock-keychain", "--disable-dev-shm-usage",
"--disable-gpu", "--dump-dom", "about:blank")
b, err := cmd.CombinedOutput()
if err != nil {
Expand Down
19 changes: 8 additions & 11 deletions page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestSetExtraHeaders(t *testing.T) {

wg := sync.WaitGroup{}
var header http.Header
s.Mux.HandleFunc("/", func(_ http.ResponseWriter, r *http.Request) {
s.Mux.HandleFunc("/set-header", func(_ http.ResponseWriter, r *http.Request) {
header = r.Header
wg.Done()
})
Expand All @@ -109,23 +109,20 @@ func TestSetExtraHeaders(t *testing.T) {
cleanup := p.MustSetExtraHeaders("a", "1", "b", "2")

wg.Add(1)
p.MustNavigate(s.URL())
p.MustNavigate(s.URL("/set-header"))
wg.Wait()

g.Eq(header.Get("a"), "1")
g.Eq(header.Get("b"), "2")

cleanup()

// TODO: I don't know why it will fail randomly
if false {
wg.Add(1)
p.MustReload()
wg.Wait()
wg.Add(1)
p.MustReload()
wg.Wait()

g.Eq(header.Get("a"), "")
g.Eq(header.Get("b"), "")
}
g.Eq(header.Get("a"), "")
g.Eq(header.Get("b"), "")
}

func TestSetUserAgent(t *testing.T) {
Expand Down Expand Up @@ -892,7 +889,7 @@ func TestFonts(t *testing.T) {
func TestPagePDF(t *testing.T) {
g := setup(t)

p := g.page.MustNavigate(g.srcFile("fixtures/click.html"))
p := g.page.MustNavigate(g.srcFile("fixtures/click.html")).MustWaitLoad()

s, err := p.PDF(&proto.PagePrintToPDF{})
g.E(err)
Expand Down
4 changes: 3 additions & 1 deletion setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func newTesterPool() rod.Pool[G] {
}

func newTester() *G {
u := launcher.New().Set("proxy-bypass-list", "<-loopback>").MustLaunch()
u := launcher.New().Set("proxy-bypass-list", "<-loopback>").NoSandbox(true).MustLaunch()

mc := newMockClient(u)

Expand Down Expand Up @@ -127,6 +127,8 @@ func setup(t *testing.T) G {

tester.checkLeaking()

tester.page.MustNavigate("")

return *tester
}

Expand Down

0 comments on commit c42b414

Please sign in to comment.